我有一个黄色,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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
编辑2
如果我将该android:clipChildren="false"属性放在父LinearLayout中,我会得到以下内容:
