Magical attribute meaning record in view

Article Directory

clipToPadding

View the comment on the attribute in android

Defines whether the ViewGroup will clip its children and resize (but not clip) any
EdgeEffect to its padding, if padding is not zero. This property is set to true by
default.

My understanding of this paragraph is: This attribute is used to define whether ViewGroup will re-cut and change the size of the child view according to the padding attribute.
After the actual test, it was found that when true, the Viewgroup will adjust the drawing area according to the padding, and the drawing will subtract the width of the padding. When set to false, the ViewGroup will not adjust the size of the drawing area, and the drawing area of ​​the subview can contain the padding. area.
The effect of clipToPadding=true
You can see the effect of

clipToPadding=false with a blank padding area around the view when scrolling.
You can see that the blank quilt view of the padding part is drawn

when scrolling. When we use the recyclerview, if we want The padding area is not visible when scrolling, we can use clipToPadding=false to achieve this effect

clipChildren

View comments in android

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. The default value of
this property is true.

The meaning of this attribute is: whether to restrict the view to draw only within its own boundaries. When performing zoom animation, when the size of the view exceeds 100%, you can set this property to false, so that the view can be displayed outside the boundary of its display area.
The effect of clipChildren=true The
picture cannot be displayed beyond the parent layout and is clipped.

Layout code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/grandfather"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="true"
    android:orientation="vertical"
    android:gravity="center"
    tools:context=".MainActivity_main">

    <LinearLayout
        android:id="@+id/father"
        android:background="#4CAF50"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:orientation="vertical">

        <ImageView
            android:src="@drawable/kite"
            android:layout_width="300dp"
            android:layout_height="300dp" />
    </LinearLayout>
</LinearLayout>

Effect of clipChildren=false

Layout code:
set the clipChildren property in the root layout in the above layout code to false

Guess you like

Origin blog.csdn.net/liu_12345_liu/article/details/111822877