Sitemap
Tung Doan

Tung Doan

I enjoy sharing what I learn about Kotlin, Jetpack, and scalable app architecture with the developer community.

clipToPadding vs clipChildren in Android XML

2 min readSep 28, 2025

--

These two attributes are often confused, but they solve different layout problems.

1. clipToPadding

What it does:

  • Controls whether the content of a ViewGroup (e.g., RecyclerView, ScrollView) can draw into the padding area.

Default: true → child views are clipped and cannot draw into padding.

When false: children can render inside the padding region.

  • Useful when you want overscroll/glow, edge effects, or animations to extend into the padding area.

Example:

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:clipToPadding="false">

<!-- Child content can draw inside padding area -->
</ScrollView>

Use cases:

  • RecyclerView with padding for spacing, but you still want items or overscroll glow to appear under that padding.
  • Carousel lists where edge items peek into the padding.

2. clipChildren

What it does:

  • Controls whether a child view is clipped to the bounds of its parent.

Default: true → child views are cut off at parent boundaries.

Get Tung Doan’s stories in your inbox

Join Medium for free to get updates from this writer.

When false: child can draw outside the parent’s bounds.

  • Useful for animations, shadows, scaling, or parallax effects where part of the child intentionally extends out.

Example:

<FrameLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:clipChildren="false">
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:scaleType="centerCrop"
android:src="@drawable/large_image"/>
</FrameLayout>

Here, the image can render outside the FrameLayout.

Use cases:

  • Card stack animations (e.g., Tinder swipe).
  • Shadows or glows that should not be cut off by parent bounds.
  • Child scale/rotation animations that overflow.

3. Quick Comparison

Press enter or click to view image in full size
clipToPadding vs clipChildren

4. Gotchas

  • They stack: a parent with clipChildren=true will still cut children even if the child’s own clipToPadding=false.
  • If you want a complex animation layout (like carousel), often you need:
android:clipToPadding="false" android:clipChildren="false"
  • clipChildren applies recursively: if a parent up the hierarchy clips, children deeper in the tree can still be cut off.

Rule of thumb:

  • Use clipToPadding="false" when you want children/scroll effects to use padding space.
  • Use clipChildren="false" when you want children to draw outside parent bounds (animations, shadows, peeking UI).

--

--

Tung Doan
Tung Doan

I enjoy sharing what I learn about Kotlin, Jetpack, and scalable app architecture with the developer community.