我有一个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中,我会得到以下结果:
发布于 2018-03-28 16:22:19
android:clipChildren="false"
允许每个子元素在父项的范围之外绘制自己的范围。它不允许子元素在父项之外绘画。为此,需要设置android:clipChildren="false"
我认为你看到的颜色只是因为颜色没有固有的界限。如果没有任何东西被剪掉,颜色就会永远消失。我的理论是,如果你使用拉伸的1x1像素而不是颜色,事情就会不同。
https://stackoverflow.com/questions/-100007839
复制相似问题