如何将中心置于相对布局的底部空间?
问题描述:
如何设计布局,使其占据相对布局的底部空间的中心。如何将中心置于相对布局的底部空间?
|--------------------------|
| |
| |
| |
| |
| |
|--------------------------|
| | |
| this will be |
| content |
| | |
| | |
|--------------------------|
<RelativeLayout>[another_layout should be here]</RelativeLayout>
所以another_layout将从RelativeLayout的中间开始,填补了该布局的底部。
答
你可以将你的内容封装在一个线性布局中,这将在你的相对布局中,然后设置android:layout_alignParentBottom =“true”。
答
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Invisible View that will hold the position -->
<View
android:id="@+id/stub"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerInParent="true"/>
<!-- Content below -->
<TextView
android:layout_below="@id/stub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/something" />
</RelativeLayout>
答
RelativeLayout是您的顶级元素吗?如果是这样,那么为什么不使用带有layout_weight
参数的LinearLayout,然后将其作为RelativeLayout
?这似乎比在你已经集中的观点下黑客更合乎逻辑。布局看起来像这样。
<LinearLayout
xmlns:android="stuff"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1">
<!-- All the stuff that would have been above the center before -->
</RelativeLayout>
<RelativeLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1">
<!-- All the stuff that would have been below the center before -->
</RelativeLayout>
IMO这是一个清晰的解决方案
其实layout_alignParentBottom不会工作。可能是我的布局图片让你困惑。我的布局结构是这样的 [此处的内容.....] RelativeLayout> –
jquery404
这是否意味着您希望您的内容位于屏幕中间的某个位置? – Aditya
是的,说我想要一个LinearLayout。它将从屏幕中间开始,其高度将为屏幕高度的一半。 – jquery404