【发布时间】:2015-06-28 07:51:54
【问题描述】:
我有以下布局
...
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight=".8">
<LinearLayout
android:layout_width="320dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerInParent="true"
android:baselineAligned="false">
<include layout="@layout/sublayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="center_vertical" />
<include layout="@layout/sublayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
...
我不明白为什么会收到警告“此 LinearLayout 布局或其 RelativeLayout 父级可能无用”。
我在布局设计中尝试将 sublayaout1 和 sublayaout2 置于屏幕中间。为此,我需要将 android:layout_centerInParent 属性设置为 true,并且我需要将 RelativeLayout 父级作为容器,因为它位于具有多行的水平 LinearLayout 内。
有没有办法在没有 RelativeLayout 的情况下将 LinearLayout 居中? 谢谢
【问题讨论】: