在我的屏幕中,我希望在顶部有 Hearder(特别是图像)和列表,在底部我希望有小图像按钮(如 youtube、facebook)。
我正在使用 RelativeLayout.. 前两个显示正确,最后一个根本不显示在屏幕上,任何人都可以在这里提供帮助。
我的布局文件是这样的
<RelativeLayout>
<image></image>
<ListView></ListView>
<RelativeLayout>
<ImageButton></ImageButton>
</RelativeLayout>
</RelativeLayout>
最佳答案
在 RelativeLayout
中,添加 subview 的顺序很重要(因为后者可以绑定(bind)到之前添加的 View )。
我认为这是你布局的问题,你有一个 fill_parent
/match_parent
high view 已经在里面(ListView
),并且没有页脚的空间。
您应该在 RelativeLayout
中更改 View 的顺序:
- 首先你应该添加标题 View
(并将其绑定(bind)到顶部:
android:align_parent_top="true"
),然后 - 带按钮的页脚(并绑定(bind)它
到底部:
android:align_parent_bottom="true"
), 和 - 应该填充的
ListView
空白空间将作为 三分之二的观点,与android:layout_below="header_view"
和adroid:layout_above
="footer_view"`
您的布局将如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout>
<image android:id="@+id/header"
android:layout_alignParentTop="true"></image>
<RelativeLayout android:id="@+id/footer"
android:layout_alignParentBottom="true">
<ImageButton></ImageButton>
</RelativeLayout>
<ListView
android:layout_below="@id/header"
android:layout_above="@id/footer"></ListView>
</RelativeLayout>
关于Android:将组件添加到 RelativeLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5988050/