Refining Android property clipToPadding

I recently worked with animation and got into trouble when I FrameLayoutdidn’t display my shadow properly due to strange reasons.

I found a good answer that helped me, but the property was used clipToPadding. The answer can be found here: Android "height" not showing a shadow

However, I really wanted to understand the purpose of this property. I went to the Android documentation which says that:

Determines whether the ViewGroup will click on its children and resize (but not the clip) any EdgeEffect to fill it, if the fill is not zero. This is set to true by default.

I read it many times, and I searched for examples on the Internet, but I really did not find them. The only visuals I found were like this difference ClipToPadding

I see the effect on the list, but how can it affect when ViewGroupthere is only one View, etc.

It would be nice if someone could provide me some key points about this property and how it works with a few examples.

+4
source share
1 answer

clipToPadding basically means "If the view extends beyond its borders into the fill area, overwrite this image with the parent addition."

. , , . , , clipToPadding=false, .

, , , ListView RecyclerView. . clipToPadding=false, , .

, . . " ", "". .

Bounds and padding

clipToPadding=true, , , :

clipToPadding = true

clipToPadding=false :

enter image description here

XML, :

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:background="#8888ff">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="40dp"
        android:paddingRight="40dp"
        android:paddingTop="20dp"
        android:paddingBottom="20dp"
        android:clipToPadding="false"
        android:layout_centerInParent="true">

        <View
            android:layout_width="170dp"
            android:layout_height="170dp"
            android:background="@drawable/oval"
            android:alpha="0.5"
            android:elevation="5dp"
            />

    </RelativeLayout>

</RelativeLayout>

oval drawable:

<shape android:shape="oval">
        <solid android:color="#f2f2f2"/>
</shape>
+4

Source: https://habr.com/ru/post/1651389/


All Articles