1、clipChildren
android:clipChildren
setClipChildren(boolean)Defines
whether a child is limited to draw inside of its bounds or not.
是否限制子视图只能在父视图范围内进行绘制,默认是true。
注意点:这个属性只存在viewGroup,并且只能放在子视图的爷爷视图,放置父视图没有效果
示例:
clipChildren=true时,可以看到超过父视图区域的部分被截断了,
<RelativeLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:background="#ff0000"
android:clipChildren="true" >
<RelativeLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:background="#ffff00" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-10dp"
android:text="123135464" />
</RelativeLayout>
</RelativeLayout>
clipChildren=false
2、clipToPadding
android:clipToPadding
setClipToPadding(boolean)Defines
whether the ViewGroup will clip its drawing surface so as to exclude the padding area.
简单来说就是,在viewgroup的padding区域绘制子视图时是否剪切掉,默认true
注意:viewGroup属性,在父视图中设置
示例:
<RelativeLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:background="#ff0000"
android:padding="20dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-10dp"
android:text="123135464" />
</RelativeLayout>
clipTopadding=false,允许子视图在padding范围内绘制
3、子视图与父控件perssed 等状态保持一致(View 属性)
xml配置:
android:duplicateParentState
代码:
setDuplicateParentStateEnabled
4、父视图与子视图pressed状态保持一致(VIewGroup属性)
xml配置:
android:addStatesFromChildren
代码:
setAddStatesFromChildren