Android布局clipChildren属性的用法

最近在一些技术群里看到有不少新手都在困惑于类似下面的一个底部tab选项卡布局。中间的是凸出来一点。类似这样:

Android布局clipChildren属性的用法


圈红框的地方上半部分明显高出根布局一些。这样的布局其实只要一个属性就可以搞定,那就是clipChildren。


用法如下:

[java] view plain copy
  1. <RelativeLayout  
  2.         android:layout_width="match_parent"  
  3.         android:layout_height="wrap_content"  
  4.         android:clipChildren="false" >  
  5.   
  6.         <LinearLayout  
  7.             android:layout_width="match_parent"  
  8.             android:layout_height="40dp"  
  9.             android:layout_alignParentBottom="true"  
  10.             android:background="#eeeeee"  
  11.             android:orientation="horizontal" >  
  12.   
  13.             <RelativeLayout  
  14.                 android:layout_width="match_parent"  
  15.                 android:layout_height="60dp"  
  16.                 android:layout_gravity="bottom" >  
  17.   
  18.                 <ImageView  
  19.                     android:layout_width="match_parent"  
  20.                     android:layout_height="match_parent"  
  21.                     android:layout_centerInParent="true"  
  22.                     android:src="@drawable/wujiaoxing1" />  
  23.             </RelativeLayout>  
  24.         </LinearLayout>  
  25.     </RelativeLayout>  

效果图:

Android布局clipChildren属性的用法


这里要注意2点:在根布局节点设置clipChildren=false,这个属性默认为true.意思是是否限制子视图在其范围内。其次就是要用layout_grivate来控制超出的部分显示位置


原文链接:https://blog.****.net/qq_17387361/article/details/53759611