2
重繪帆布我有一個擴展視圖類和具有的onDraw方法來實現 在我的XML文件我有我的觀點一的FrameLayout和RelativeLayout的一個按鈕如何在一個視圖從活動
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<canvas.pruebas.MyView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/btn"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="hello"
android:textSize="15sp"
/>
</RelativeLayout>
</FrameLayout>
在我的Activity類中,我想實現當我單擊按鈕時重畫MyView類中的畫布
public class CanvasActivity extends Activity {
Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//redraw canvas
}
});
}
}
我該怎麼做?
感謝,這是我需要 – jos11 2013-05-11 22:16:53
@ jos11。如果這對你有用,你能接受它作爲答案嗎? – petey 2017-03-16 18:44:31
對不起,你的答案從來沒有被接受,但從我+1做我需要的東西! – kalenpw 2017-06-22 22:34:18