【问题标题】:XML layout does not show correctlyXML 布局未正确显示
【发布时间】:2011-01-24 16:48:45
【问题描述】:

我真的很难弄清楚这里发生了什么。我有这个描述布局的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical" 
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

   <SurfaceView android:id="@+id/surface"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center">
    </SurfaceView>

   <TextView android:id="@+id/text_kb_streamed"
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content"
             android:textStyle="bold" 
             android:text="Streaming .mp3 Audio Tutorial" />

   <ProgressBar android:id="@+id/progress_bar"
                android:layout_width="200px" 
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                style="?android:attr/progressBarStyleHorizontal"/>

   <ImageButton android:id="@+id/button_play"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_marginTop="5px" 
                style="?android:attr/buttonStyleSmall"
                android:src="@drawable/button_pause" />
</LinearLayout>

但是当它被绘制时,它只是显示一个空的黑屏。我在我的活动中调用 setContentView。实际上,我发现如果我删除 SurfaceView 标签,它就会被正确绘制。

谁能帮我知道发生了什么? 谢谢

编辑:感谢答案,我发现 SurfaceView 占用了所有空间,因此按钮不可见。关于如何避免这种情况的任何想法? 谢谢

【问题讨论】:

  • 我从未使用过 SurfaceView,它是否有任何内在维度可以环绕?看起来它占用了所有空间。我会尝试给它一些固定的小高度,比如 20px。
  • 您是否碰巧将 setZOrderOnTop 设置为 true?
  • @bigstones 没错,如果我将其设置为 20 像素,则其余显示。所以它肯定会占用所有空间
  • @Nick Campion 我不使用该功能 AFAK(除非它被自动调用)

标签: android android-layout surfaceview


【解决方案1】:

尝试将 SurfaceView 更改为:

   <SurfaceView android:id="@+id/surface"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="center">
</SurfaceView>

这将导致它仅填充线性布局中其他视图未使用的可用高度。

【讨论】:

    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多