clipChildren用法介绍

来源:互联网 发布:广东广电网络收费标准 编辑:程序博客网 时间:2024/06/03 19:21
android:clipChildren先看官方介绍
Defines whether a child is limited to draw inside of its bounds or not. 
This is useful with animations that scale the size of the children to more than 100% for instance. 
In such a case, this property should be set to false to allow the children to draw outside of their bounds.
意思是说,通过设置clipChildren可以是子视图超出其layout范围绘画,默认是不允许的。
一般情况下不会使用到该属性,因为需要多嵌套一层甚至多层,在复杂的布局中会影响到layout的效率。
但是是动画方面却很有用途。看下图
clipChildren=true时,
clipChildren=false时,
layout.xml
[html] view plain copy
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="match_parent"  
  3.     android:layout_height="match_parent"  
  4.     android:clipChildren="false"  
  5.     android:gravity="center">  
  6.   
  7.     <LinearLayout  
  8.         android:layout_width="100dp"  
  9.         android:layout_height="100dp"  
  10.         android:background="@android:color/darker_gray"  
  11.         android:gravity="center">  
  12.   
  13.         <TextView  
  14.             android:layout_width="wrap_content"  
  15.             android:layout_height="wrap_content"  
  16.             android:background="@android:color/holo_red_dark"  
  17.             android:onClick="click"  
  18.             android:text="Test"  
  19.             android:textSize="28sp" />  
  20.   
  21.     </LinearLayout>  
  22.   
  23.   
  24. </LinearLayout>  
scale.xml
[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <scale xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:duration="2000"  
  4.     android:fromXScale="1.0"  
  5.     android:fromYScale="1.0"  
  6.     android:pivotX="50%"  
  7.     android:pivotY="50%"  
  8.     android:toXScale="8.0"  
  9.     android:toYScale="8.0"></scale>  
java code
[html] view plain copy
  1. public void click(View view) {  
  2.         Toast.makeText(this, "onClick", Toast.LENGTH_LONG).show();  
  3.         Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale);  
  4.         view.startAnimation(animation);  
  5.     }  
    1 0