私のAPPでは、特定のゲームコントロール(control_1、control_2)を保持するgametaskbarを取得しました。さらに、可視性を切り替えることができる 2 つのボタン (Button_1、Button_2) があります。UI の変更が多いため、この可視性の切り替えは asynctask の onPostexecute() で行います。これは、Android 4.0 より前のすべてのテスト済みデバイスでうまく機能します。しかし、4.0 以上のデバイスでは、ボタンの 1 つの表示を切り替えると、ゲーム タスクバーの背景画像が削除されます。これはあってはならないことであり、どこを見ればよいかわかりません。
ビュー階層の下部に glsurfaceview を含むフレームレイアウトがあります。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/baseframe"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<LinearLayout
android:id="@+id/glSurfaceHolder"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="@+id/GameTaskbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:background="@drawable/bar"
android:orientation="horizontal"
android:visibility="invisible" >
<Button
android:id="@+id/control_1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:layout_margin="1dp"
android:background="@drawable/blind" >
</Button>
<Button
android:id="@+id/control_2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:layout_margin="1dp"
android:background="@drawable/blind" >
</Button>
</LinearLayout>
<Button
android:id="@+id/Button_1"
android:layout_width="75dp"
android:layout_height="50dp"
android:layout_gravity="right|center_vertical"
android:background="@drawable/drop_64"
android:visibility="invisible" >
</Button>
<Button
android:id="@+id/Button_2"
android:layout_width="75dp"
android:layout_height="50dp"
android:layout_gravity="left|center_vertical"
android:background="@drawable/back_64"
android:visibility="invisible" >
</Button>
</FrameLayout>
これは、可視性を切り替える部分です。
protected void onPostExecute() {
if(button_1_state){
Button_1.setVisibility(View.VISIBLE);
}
else{
Button_1.setVisibility(View.INVISIBLE);
}
if(button_2_state){
Button_2.setVisibility(View.VISIBLE);
}
else{
Button_2.setVisibility(View.INVISIBLE);
}
...
}
この投稿 ( SurfaceView の上でビューを更新するとエラーが発生する) によると、Android4.0 固有の不要な動作を不要な backgroundvisibilityswitch に減らすことができました。
また、ボタンで requestFocus() を試してみましたが、うまくいきませんでした。
デバッグすると、すべてが正しいように見え、gametaskbar.getVisibility() = 0 になります。しかし、async-onPostexecute() を終了すると、背景画像が消えます。この状況でボタンの表示を非表示に切り替えないと、背景画像も残ります。私が使用していない間違ったIDを使用しているように。
エミュレータでもこの動作を再現できます。
PS:ボタンの可視性は必要に応じて変更されます
多分誰かがアイデアを持っています。