0

在我的应用程序中,我有一个包含特定游戏控件(control_1,control_2)的游戏任务栏。另外我有两个按钮(Button_1,Button_2),我可以在其中切换可见性。因为我有很多 UI 更改,所以我在异步任务的 onPostexecute() 中进行了可见性切换。这适用于 android 4.0 之前的所有测试设备。但是> 4.0设备在切换其中一个按钮的可见性时会删除我的游戏任务栏的背景图像。这不应该发生,我没有更多的想法去哪里看。

我在视图层次结构的底部有一个带有 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 上刷新 View 时出错),我能够将 Android4.0 特定的不需要的行为减少为不需要的 backgroundvisibilityswitch。

我也尝试过按钮上的 requestFocus() ,但没有运气。

当我调试它时,一切看起来都应该并且 gametaskbar.getVisibility() = 0。但是在离开 async-onPostexecute() 之后,背景图像消失了。在这种情况下,当我不将按钮可见性切换为不可见时,背景图像也会保留。就像我使用了我没有使用的错误 ID。

即使在模拟器中,我也可以重现这种行为。

ps:按钮可见性根据需要更改

也许有人有一个想法。

4

1 回答 1

0

修复了这个:将带有 GameTaskBar 背景图像的 LinearLayout 更改为另一个 FrameLayout,Imageview 在原始 LinearLayout 下方,带有控件

<FrameLayout
    android:id="@+id/GameTaskbar"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_gravity="bottom"
    android:visibility="invisible" >

    <ImageView
        android:id="@+id/bar"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:src="@drawable/bar_512_2"
        android:contentDescription="@string/bar"/>

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <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>
</FrameLayout>

奥奈

于 2012-06-02T16:20:06.930 回答