gpt4 book ai didi

android - 无法让 clipChildren=false 属性起作用

转载 作者:IT老高 更新时间:2023-10-28 22:00:23 45 4
gpt4 key购买 nike

我有一个黄色 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":

enter image description here

红色的LinearLayout按预期剪裁

  • android:clipChildren="false":

enter image description here

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 中,我会得到以下信息:

enter image description here

最佳答案

android:clipChildren="false" 允许每个 child 在其自己的边界之外,在 parent 之内进行绘制。它不允许 child 在 parent 本身之外进行绘画。为此,您需要在祖 parent (以及)上设置 android:clipChildren="false"

我认为您所看到的颜色只是因为颜色没有固有的界限。如果没有任何东西剪裁它们,颜色就会永远消失。我的理论是,如果你使用拉伸(stretch)的 1x1 像素图像而不是颜色,情况会有所不同。

关于android - 无法让 clipChildren=false 属性起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15975725/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com