0

替代文字

上图是我游戏的第一页。通常大的蓝色“按钮”背景图像不应该出现在那里。

我在布局文件中为按钮声明自定义背景图像,如下所示:

<Button android:id="@+id/id_button_startgame"
                             android:layout_width="wrap_content"
                             android:layout_height="48dp"
                             android:layout_weight="1"
                             android:textSize="26sp"
                             android:text="@string/start_game"
                             android:textColor="@color/solid_red"
                             android:background="@drawable/button_bg"

                             />

这是drawable文件夹中的button_bg.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/button01_focused" /> 
    <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/button01_pressed" /> 
    <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/button01_pressed" /> 
    <item android:drawable="@drawable/button01_idle" /> 
</selector>

如您所见。下面的三个按钮是正常情况。我在我的应用程序中到处使用它们。但有时屏幕中央的那个会出现。这个大按钮不能按下或任何东西。它就在我的游戏上方盘旋。我可以开始游戏,但显然看不到内容,因为这个蓝色的大东西覆盖了所有内容。

我可以通过多次启动/退出我的游戏来重现此错误。

我很乐意提供更多信息。但不知道我应该给你什么信息。我用来FrameLayout将 UI 放在 SurfaceView 之上。

而且大多数时候这个错误不会发生。在我启动/退出游戏并重复几次后,它似乎随机发生。

以前有人见过这样的东西吗?如果是这样,请告诉我您是如何解决的?

4

2 回答 2

1

问题解决了。谢谢大家。

解决方案:“不要在布局上使用透明背景”

您的回答结合起来帮助我解决了这个问题。

好的,首先。我找到了一种 100% 重现错误的方法。

我有另一个活动,一个“暂停游戏”活动,它具有半透明背景,启动时将悬停在所有内容上。

要重现错误: 1. 启动“暂停”活动。2. 滑开键盘。3. 这个bug会出现在'Pause'活动的后面。

@Orsol - 是的,我对包含这些按钮的布局使用透明背景

<LinearLayout android:id="@+id/bottom_ui_container"
                android:orientation="vertical"
                android:background="@drawable/transparent_background"
                android:gravity="bottom"
                 android:layout_width="match_parent"
                android:layout_height="match_parent">

                    <LinearLayout android:id="@+id/title_button_container"
                        android:orientation="horizontal"
                         android:background="@drawable/transparent_background"
                        android:gravity="center"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:visibility="gone">

这 2 个布局是让 3 个按钮在底部水平对齐,就像在 SS 中一样。仍然不明白为什么在我滑动打开键盘后我的“按钮背景”成为布局的背景......

@mbanzon 和 Cristian - 感谢您的提示!=) 下次遇到问题时,我很想和hierarchyviewer一起玩!顺便说一句。我使用相机拍摄了这张照片,因为那时我不知道何时/如何重现该错误。

@Octavian Damiean 和 CaseyB - 感谢您的帮助!=) 我现在不会发布我的布局,因为它已经解决了。

再次感谢大家!没有你,我永远不会解决这个问题!

于 2010-09-29T14:49:37.640 回答
0

我遇到过同样的问题。在我的情况下,屏幕背景设置为

 <color name="transparent">#00000000</color>

问题已通过将其替换为

<color name="transparent">@android:color/transparent</color>
于 2010-09-30T08:05:33.587 回答