2

我真的很难弄清楚这里发生了什么。我有这个描述布局的 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 占用了所有空间,因此按钮不可见。关于如何避免这种情况的任何想法?谢谢

4

2 回答 2

4

尝试将 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>

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

于 2011-01-24T17:35:04.700 回答
1

请参考http://developer.android.com/guide/topics/graphics/index.html 它可能对您有所帮助。

于 2011-01-24T17:34:23.697 回答