in my APP I got a gametaskbar which holds specific gamecontrols (control_1, control_2). Additionaly I have two Buttons (Button_1, Button_2) where I can switch visibility. Because I have a lot of UI-Changes, I do this visibility-switching in onPostexecute() of an asynctask. This works well on all tested devices prior android 4.0. But >4.0 devices delete the background-image of my gametaskbar when switching visibility of one of the buttons. This shouldn`t happen and I have no more ideas where to look.
I have a framelayout with glsurfaceview on bottom of the view hierarchy.
<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>
this is the part where I switch visibilty:
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);
}
...
}
According to this post ( Error when refreshing View on top of SurfaceView ) I was able to reduce the Android4.0 specific unwanted behaviour to the unwanted backgroundvisibilityswitch.
I`ve also tried requestFocus() on the buttons without luck.
When I debug it, everything looks like it should and gametaskbar.getVisibility() = 0. But after leaving the async-onPostexecute() the backgroundimage disappear. When I do not switch buttonvisibility to invisible in this situation, the backgroundimage will also stay. Like I use wrong IDs which I do not.
Even in the emulator I can reproduce this behaviour.
ps: the buttonvisibility changes as wanted
Maybe someone has an idea.