2

我在 android FrameLayout 中遇到了一个非常奇怪的问题。

我正在尝试一个非常简单的游戏,它有一个 SurfaceView,当游戏结束时,我想在顶部弹出另一个视图,可能显示一些文本。这与 android 示例 lunarlander 代码非常相似。但是我无法让它工作。这是一个奇怪的问题:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/game_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<com.tmh.FunMatch.MainGamePanel
  android:id="@+id/game_panel"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"/>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <com.tmh.FunMatch.MyText
      android:id="@+id/text"
      android:text="test"
      android:visibility="invisible"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      android:gravity="center_horizontal"
      android:textColor="#88ffffff"
      android:textSize="24sp"/>
 </RelativeLayout>

对于上面的 FrameLayout,我想在游戏结束时显示第二个 TextView。但是,在我调用 TextView.setVisibility(VISIBLE) 后它不会显示。

我做了很多实验,如果我最初将 TextView 设置为 VISIBLE,然后在某些时候在代码中将其设置为 INVISIBLE。(我的理解是 TextView 必须最初显示在屏幕上一次然后我把它变成 INVISIBLE)。如果我这样做了,当游戏结束时,TextView 将正确显示。

我高度怀疑这是一个android错误。我更改了 android LunarLander 代码,我不知道为什么 LunarLander 确实工作并在屏幕上显示文本。

如果有人遇到同样的问题,请告诉我我的代码有什么问题或者是否有隐藏的错误?

谢谢

4

0 回答 0