【发布时间】:2016-07-11 15:29:17
【问题描述】:
我在布局相对布局时遇到问题。这是测试代码
<RelativeLayout
android:background="@drawable/bg_controls"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/controls_layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/controls_layout" />
</RelativeLayout>
结果是
如果我删除 android:layout_centerInParent="true" 一切正常。否则为什么 RelativeLayout 不能做到这一点?
UPD:预期结果是在 LinearLayout 下出现第二个按钮。
【问题讨论】:
-
你到底想做什么?
-
预期的结果是第二个按钮出现在 LinearLayout 下。我认为这很明显......
-
线性布局下,是不是线性布局下?
-
您能否更具体地介绍一下图片本身而不是布局?
-
RelativeLayout 在这种情况下表现正确,您需要添加 layout_below 参数以获得按钮 2 的预期结果
标签: android android-layout android-relativelayout