36

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 に属性を配置すると、次のようになります。

ここに画像の説明を入力

4

3 に答える 3

91

android:clipChildren="false"各子が、親内で独自の境界の外に描画できるようにします。子が親自体の外に描画することはできません。android:clipChildren="false"そのためには、祖父母も設定する必要があります。

あなたが色で見ているのは、色には固有の境界がないからだと思います. それらをクリッピングするものがない場合、色は永遠に続きます。私の理論では、たとえば、色の代わりに引き伸ばされた 1x1 ピクセルの画像を使用すると、状況が変わるというものです。

于 2014-10-23T13:08:08.147 に答える
28

こちらもセット

android:clipToPadding="false"

それ以外:

android:clipChildren="false"
于 2016-10-24T08:01:04.937 に答える