android:clipChildren妙用:底部的radioGroup中间的button突出




在我不知道这个属性之前,底部菜单栏的布局需要写RelativeLayout来完成,但是,在我知道之后,妈妈再也不让我用RelativeLayout了。

     接下来,先认识下android:clipChildren这个属性:是否限制子View在其范围内,默认为true,在这里,我们需要把他设置为false。

先看下用了这个属性之后,实现这个布局的代码:

[java]  view plain  copy
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="fill_parent"  
  3.     android:layout_height="fill_parent"  
  4.     android:layout_gravity="bottom"  
  5.     android:clipChildren="false"  
  6.     android:gravity="bottom"  
  7.     android:orientation="vertical" >  
  8.   
  9.     <TextView  
  10.         android:id="@+id/textView1"  
  11.         android:layout_width="match_parent"  
  12.         android:layout_height="match_parent"  
  13.         android:text="TextView" />  
  14.   
  15.     <LinearLayout  
  16.         android:layout_width="match_parent"  
  17.         android:layout_height="50dp"  
  18.         android:layout_gravity="bottom"  
  19.         android:background="#234221"  
  20.         android:gravity="bottom" >  
  21.   
  22.         <ImageView  
  23.             android:id="@+id/imageView1"  
  24.             android:layout_width="0dp"  
  25.             android:layout_height="fill_parent"  
  26.             android:layout_weight="1"  
  27.             android:src="@drawable/ic_launcher" />  
  28.   
  29.         <ImageView  
  30.             android:id="@+id/imageView2"  
  31.             android:layout_width="0dp"  
  32.             android:layout_height="fill_parent"  
  33.             android:layout_weight="1"  
  34.             android:src="@drawable/ic_launcher" />  
  35.   
  36.         <ImageView  
  37.             android:id="@+id/imageView3"  
  38.             android:layout_width="0dp"  
  39.             android:layout_height="80dp"  
  40.             android:layout_gravity="bottom"  
  41.             android:layout_weight="1"  
  42.             android:src="@drawable/ic_launcher" />  
  43.   
  44.         <ImageView  
  45.             android:id="@+id/imageView4"  
  46.             android:layout_width="0dp"  
  47.             android:layout_height="fill_parent"  
  48.             android:layout_weight="1"  
  49.             android:src="@drawable/ic_launcher" />  
  50.   
  51.         <ImageView  
  52.             android:id="@+id/imageView5"  
  53.             android:layout_width="0dp"  
  54.             android:layout_height="fill_parent"  
  55.             android:layout_weight="1"  
  56.             android:src="@drawable/ic_launcher" />  
  57.     </LinearLayout>  
  58.   
  59. </LinearLayout>  
是不是 感觉很惊讶,不用什么RelativeLayout布局,也不用重叠,简单的LinearLayout就可以轻松实现.只需以下步骤:

1、只需在根节点设置android:clipChildren为false即可,默认为true(经过测试,其实是在他爹的爹设置,也就是他爷爷节点设置)

2、可以通过android:layout_gravity控制超出的部分如何显示。


在我不知道这个属性之前,底部菜单栏的布局需要写RelativeLayout来完成,但是,在我知道之后,妈妈再也不让我用RelativeLayout了。

     接下来,先认识下android:clipChildren这个属性:是否限制子View在其范围内,默认为true,在这里,我们需要把他设置为false。

先看下用了这个属性之后,实现这个布局的代码:

[java]  view plain  copy
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="fill_parent"  
  3.     android:layout_height="fill_parent"  
  4.     android:layout_gravity="bottom"  
  5.     android:clipChildren="false"  
  6.     android:gravity="bottom"  
  7.     android:orientation="vertical" >  
  8.   
  9.     <TextView  
  10.         android:id="@+id/textView1"  
  11.         android:layout_width="match_parent"  
  12.         android:layout_height="match_parent"  
  13.         android:text="TextView" />  
  14.   
  15.     <LinearLayout  
  16.         android:layout_width="match_parent"  
  17.         android:layout_height="50dp"  
  18.         android:layout_gravity="bottom"  
  19.         android:background="#234221"  
  20.         android:gravity="bottom" >  
  21.   
  22.         <ImageView  
  23.             android:id="@+id/imageView1"  
  24.             android:layout_width="0dp"  
  25.             android:layout_height="fill_parent"  
  26.             android:layout_weight="1"  
  27.             android:src="@drawable/ic_launcher" />  
  28.   
  29.         <ImageView  
  30.             android:id="@+id/imageView2"  
  31.             android:layout_width="0dp"  
  32.             android:layout_height="fill_parent"  
  33.             android:layout_weight="1"  
  34.             android:src="@drawable/ic_launcher" />  
  35.   
  36.         <ImageView  
  37.             android:id="@+id/imageView3"  
  38.             android:layout_width="0dp"  
  39.             android:layout_height="80dp"  
  40.             android:layout_gravity="bottom"  
  41.             android:layout_weight="1"  
  42.             android:src="@drawable/ic_launcher" />  
  43.   
  44.         <ImageView  
  45.             android:id="@+id/imageView4"  
  46.             android:layout_width="0dp"  
  47.             android:layout_height="fill_parent"  
  48.             android:layout_weight="1"  
  49.             android:src="@drawable/ic_launcher" />  
  50.   
  51.         <ImageView  
  52.             android:id="@+id/imageView5"  
  53.             android:layout_width="0dp"  
  54.             android:layout_height="fill_parent"  
  55.             android:layout_weight="1"  
  56.             android:src="@drawable/ic_launcher" />  
  57.     </LinearLayout>  
  58.   
  59. </LinearLayout>  
是不是 感觉很惊讶,不用什么RelativeLayout布局,也不用重叠,简单的LinearLayout就可以轻松实现.只需以下步骤:

1、只需在根节点设置android:clipChildren为false即可,默认为true(经过测试,其实是在他爹的爹设置,也就是他爷爷节点设置)

2、可以通过android:layout_gravity控制超出的部分如何显示。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值