來(lái)自ViewGroup中的屬性clipChildren用于定義一個(gè)子元素是否被限制在其父元素中進(jìn)行繪制。通常用于動(dòng)畫(huà)效果中繪制需要超出原有尺寸限制的元素時(shí)使用。在這種情況下,需要將該屬性值設(shè)置為false以確保該元素可以超出邊界。缺省值為true,也即子元素不可以超出父元素的邊界。
需要重點(diǎn)注意的是,屬性值
clipChildren需要被設(shè)置到爺爺節(jié)點(diǎn)上。
以下為布局的示例:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:clipChildren="false"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal">
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="0dp"
android:layout_height="96dp"
android:layout_gravity="bottom"
android:layout_weight="2"/>
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
重點(diǎn)關(guān)注根節(jié)點(diǎn)的屬性android:clipChildren="false"和第三個(gè)ImageView的屬性android:layout_gravity="bottom",最終效果如下所示:

clipChildren效果
而去除第三個(gè)ImageView的屬性android:layout_gravity="bottom"后的效果為:

layout_gravity未設(shè)置
可以看到,默認(rèn)頂部對(duì)齊,最終只顯示了一部分。
只去除根節(jié)點(diǎn)的屬性android:clipChildren="false"后顯示如下:

clipChildren未設(shè)置
三張圖片對(duì)比,可以很容易看出該屬性值的作用。