如何设置具有顶部、中心和底部元素的布局?
我有 2 个 LinearLayouts 和一个相对布局中的按钮。 它们应该看起来像这样:
带有顶栏的 LinearLayout(约占屏幕的 20%)
滚动视图中的许多元素占据了大部分屏幕(约占屏幕的 60%)
底部的按钮(约占 屏幕的 60%) . 20% 的屏幕)
我已经尝试过:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/layoutTopBlack"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<include layout="@layout/top_black_bar_cancel_register_button"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layoutCenter"
android:layout_below="@id/layoutTopBlack"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="@layout/top_black_bar_cancel_register_button"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/buttonNextStep"
android:text="@string/next_step"
style="@style/mainButtonStyle"/>
</RelativeLayout>
这不起作用。布局中心位于按钮上方,因此我从未看到该按钮。
有什么建议吗?
提前致谢。
编辑: 我从编辑那里找到了这个: 无法解析资源@id/layoutTopBlack
I have 2 LinearLayouts and a button within a relative layout.
They should look like this:
A LinearLayout with a top bar (Approx. 20% of the screen)
Lots of elements in a scrollview which takes up most of the screen (Approx. 60% of the screen)
A Button at the bottom (Approx. 20% of the screen)
I have tried this:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/layoutTopBlack"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<include layout="@layout/top_black_bar_cancel_register_button"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layoutCenter"
android:layout_below="@id/layoutTopBlack"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="@layout/top_black_bar_cancel_register_button"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/buttonNextStep"
android:text="@string/next_step"
style="@style/mainButtonStyle"/>
</RelativeLayout>
This does not work. The layoutCenter lays itself over the button, so i never see the button.
Any suggestions?
Thanks in advance.
Edit:
I found this from the editor:
Couldn't resolve resource @id/layoutTopBlack
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需告诉您的布局中心将其自身布局在按钮上方,如下所示:
Just tell your layoutCenter to layout itself above the button, something like this:
实际上,考虑到您提到的百分比,您可能希望将
LinearLayout
与 布局权重在这里,而不是RelativeLayout。EG 执行您提到的 20% / 60% / 20% 权重:
如果顶部/底部栏只需要保留其内容,而不是占据固定百分比,那么 renam.antune 的答案应该有效,或者您可以使用 < code>LinearLayout 与上面类似,但设置顶部/底部栏来包装内容而不在其上设置权重。然后,中心视图上的任何权重都会使其填充所有可用的剩余空间,而不会像使用
fill_parent
那样擦除按钮。Actually, given the percentages you mentioned, you'd probably want to use a
LinearLayout
with layout weights here, not a RelativeLayout.EG to do the 20% / 60% / 20% weight you mentioned:
If the top/bottom bars just need to hold their content, not take up a fixed percentage, then renam.antune's answer should work, or you could use a
LinearLayout
like above but set the top/bottom bars to wrap content without setting a weight on them. Then any weight on the center view will make it fill out all available remaining space without wiping out the button like it would with afill_parent
.