XML 布局无法正确显示
我真的很难弄清楚这里发生了什么。我有一个描述布局的 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 占用了所有空间,因此按钮不可见。关于如何避免这种情况的任何想法? 谢谢
I'm really having a hard time trying to figure out what's going on here. I have this xml file describing a layout:
<?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>
But when it comes to get drawn, it just shows an empty black screen. I call setContentView in my activity. Actually, I've found out that if I remove the SurfaceView tag, it gets drawn correctly.
Can anyone help me out to know what's happening?
Thanks
Edit: Thanks to the answers, I've found out that the SurfaceView is taking all the space so the buttons are not visible. Any ideas on how can I avoid that?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将 SurfaceView 更改为:
这将导致它仅填充线性布局中其他视图未使用的可用高度。
Try changing the SurfaceView to:
This will cause it to fill only the available height unused by the other views in the linear layout.
请参考http://developer.android.com/guide/topics/graphics/index .html
它可能对你有帮助。
Please refer http://developer.android.com/guide/topics/graphics/index.html
it may help you.