릴레이티브레이아웃 안에 프레임레이아웃을 두고
그 프레임레이아웃에 View를 상속받은 CustomView 클래스를
addView시켜서 화면에 나타내고 있습니다.
여기까진 아무런 문제가 없습니다..
그런데 버튼을 추가시키려고 xml파일에 버튼을 정의하고 잘 나타나나싶어 에뮬을 돌려보니
java파일에 단 한줄의 코드도 없이 레이아웃만 정의한 버튼을 클릭했을때 Custom뷰의 onDraw()함수가 호출됩니다;;;;;
계속 호출되는건 아니고
버튼을 처음 누를땐 onDraw()함수가 2번호출..
다시 한번더 버튼을 누르면 onDraw()가 1번 호출..
그다음부턴 반응을 하진 않습니다..;; 도대체 왜이런건가요 ㅠㅠ
소스 첨부합니다..
JAVA파일
.........
public class test extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.test);
FrameLayout fr = (FrameLayout) findViewById(R.id.frame);
MyView vw = new MyView(this);
fr.addView(vw);
}
protected class MyView extends View {
int count = 0;
public MyView(Context context) {
super(context);
}
public void onDraw(Canvas canvas) {
// 테스트해보려고 작성한것입니다.
count++;
Paint pnt = new Paint();
canvas.drawText("Count : " + count, 10, 10, pnt);
}
}
}
XML파일
....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/view_bg">
<FrameLayout
android:id="@+id/frame"
android:layout_width="300dip"
android:layout_height="200dip"
android:layout_marginTop="130dip"
android:layout_marginLeft="10dip"
android:background="#000000"
>
</FrameLayout>
<Button
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
/>
</RelativeLayout>
처음 실행을 하면 count값은 1
test버튼을 한번 눌러보면 count값은 3
다시 한번더 누르면 count는 4
그다음부터는 버튼을 눌러도 아무런 반응이 없습니다..
고수님들 이유좀 알려주세요 ㅠㅠ