clipChildren屬性


clipChildren屬性表示是否限制子控件在該容器所在的范圍內,clipChildren屬性配合layout_gravity屬性,可以用來設置多余部分的顯示位置,我這里舉一個簡單的例子,比如喜馬拉雅FM這個應用的首頁:

大家注意看這個應用底部導航欄中中間一個是要比另外四個高的,這種效果很多人就會想到使用一個RelativeLayout布局來實現,其實不用那么麻煩,這種效果一個clipChildren屬性就能實現,示例Demo如下:

代碼:

<?xml version="1.0" encoding="utf-8"?>  
<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="match_parent"  
    android:clipChildren="false"  
    tools:context="org.lenve.clipchildren.MainActivity">  
  
    <LinearLayout  
        android:layout_width="match_parent"  
        android:layout_height="48dp"  
        android:layout_alignParentBottom="true"  
        android:background="#03b9fc"  
        android:orientation="horizontal">  
  
        <ImageView  
            android:layout_width="0dp"  
            android:layout_height="match_parent"  
            android:layout_weight="1"  
            android:src="@mipmap/ic_launcher"/>  
  
        <ImageView  
            android:layout_width="0dp"  
            android:layout_height="match_parent"  
            android:layout_weight="1"  
            android:src="@mipmap/ic_launcher"/>  
  
        <ImageView  
            android:layout_width="0dp"  
            android:layout_height="72dp"  
            android:layout_gravity="bottom"  
            android:layout_weight="1"  
            android:src="@mipmap/ic_launcher"/>  
  
        <ImageView  
            android:layout_width="0dp"  
            android:layout_height="match_parent"  
            android:layout_weight="1"  
            android:src="@mipmap/ic_launcher"/>  
  
        <ImageView  
            android:layout_width="0dp"  
            android:layout_height="match_parent"  
            android:layout_weight="1"  
            android:src="@mipmap/ic_launcher"/>  
    </LinearLayout>  
</RelativeLayout> 

大家看只需要在根節點添加clipChildren屬性,然后在第三個ImageView上添加layout_gravity屬性即可,layout_gravity屬性值為bottom表示控件大小超出后控件底部對齊。效果如下:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM