ユーザーが画面をタップした時点でボール (ビットマップ) がキャンバスに表示されるアプリに取り組んできました。背景は xml レイアウト setContentView(R.layout.newsession) です。キャンバスは黒塗りのキャンバスです。Java 親クラス setContentView(customView) を設定すると、プログラムは正常に動作しますが、カスタム サーフェス ビューを XML レイアウトと setContentView(R.layout.newsession) に追加すると、画面にはキャンバスが表示されるだけで、OnTouch イベントは表示されません。動作しません。私は何か間違ったことをしていますか?私はこれにほぼ1週間取り組んでおり、本当に助けが必要です. XML レイアウトとカスタム surfaceView のコードを以下に掲載します。前もって感謝します!
XML レイアウト (ニュースセッション)
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/newSessionPage"
>
<ImageView
android:layout_width="231dp"
android:id="@+id/ivStrikeGrid"
android:layout_gravity="center"
android:layout_height="270dp"
android:layout_marginTop="18dp"
android:src="@drawable/strike_grid"
android:layout_marginBottom="10dp"
/>
<appsys.studios.CustomSurfaceViewOne
android:id="@+id/customSurfaceViewOne1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></appsys.studios.CustomSurfaceViewOne
>
</FrameLayout>
カスタム SurfaceView
package appsys.studios;
public class CustomSurfaceViewOne extends SurfaceView implements Runnable{
public CustomSurfaceViewOne(Context context, AttributeSet attr) {
super(context, attr);
ourHolder = getHolder();
}
// Other stuff
}
次のようにうまく動作します:
newSeshView = new CustomSurfaceViewOne(this, null);
setContentView(newSeshView);
しかし、次のように XML レイアウトから使用しようとしても何も起こりません。
newSeshView = new CustomSurfaceViewOne(this, null);
setContentView(R.layout.newsession);
再度、感謝します!:)