【发布时间】:2013-04-05 05:43:25
【问题描述】:
我有一个黄色的RelativeLayout,其中包含一个更高的红色LinearLayout。
为了让整个LinearLayout可见,我设置了android:clipChildren="false",但这并没有按预期工作:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="44dp"
android:background="#FFFF00"
android:clipChildren="false" >
<LinearLayout
android:layout_width="50dp"
android:layout_height="100dp"
android:background="#FF0000"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
-
android:clipChildren="true":
红色的LinearLayout 按预期剪裁
-
android:clipChildren="false":
LinearLayout 的高度被剪裁,并且布局中设置的宽度不受尊重。
怎么了?
编辑
如果我将容器包装在 LinearLayout 中,并且两个尺寸都与其父级匹配,我会得到相同的结果(我检查了 LinearLayout 容器的容器是否填满了整个屏幕)。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="44dp"
android:background="#FFFF00"
android:clipChildren="false" >
<LinearLayout
android:layout_width="50dp"
android:layout_height="100dp"
android:background="#FF0000"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
</LinearLayout>
编辑 2
如果我将 android:clipChildren="false" 属性放在父 LinearLayout 中,我会得到以下信息:
【问题讨论】:
-
相对布局有android:layout_height="44dp"。它本身被其父级剪辑
-
我直接用 setContentView(R.layout.test); 设置了这个布局。没有明确的父母。根视图组不会填满整个屏幕吗?又为什么修改了LinearLayout的宽度?
-
@njzk2:为了进行更多测试,我尝试了不同的布局,但仍然无法正常工作(请参阅我的编辑)
-
你必须把 android:clipChildren="false" 放在父 LinearLayout 中
-
还是不行。请参阅我的第二次编辑。