だから私はCustomView
から拡張された を持っていView
ます。そして、XML からの線形レイアウトがあります。という名前の XML example
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/jembalang.comfest.game"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<jembalang.compfest.game.GameThread
android:id="@+id/game_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</jembalang.compfest.game.GameThread>
<Button
android:text="Button"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
そして、xmlを使用したコード
setContentView(R.layout.cobagabung);
gameView = (GameThread) Jembalang.this.findViewById(R.id.game_view);
gameView.setFocusable(true);
gameView.setFocusableInTouchMode(
gameView.start();
それが役立つ場合は、GameThread コンストラクターを追加しました
public class GameThread extends View implements Runnable,OnKeyListener{
public GameThread(Context context,AttributeSet attr){
super(context, attr);
...
}
public GameThread(Context context) {
super(context);
...
}
私のやり方には何か問題があると
思いfindViewById
ます.null
CustomView
GameThread