Nested Scrolling Containers
ID |
kotlin.android_nested_scrolling |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Reliability |
Language |
Kotlin |
Tags |
android, best-practice, reliability |
Description
Reports scrollable containers (ScrollView, HorizontalScrollView, ListView, GridView, RecyclerView, ViewPager, NestedScrollView) that are nested inside another scrollable container in the same layout file. Nested scrolling causes jittery, broken, or completely unresponsive scroll behavior.
Rationale
When a scrollable view is placed inside another scrollable view, touch events are ambiguous: the framework cannot decide which container should consume the scroll gesture. This results in choppy scrolling, partial scrolls, or the inner container being completely unscrollable. The problem is especially severe with ListView and GridView, which also compute incorrect heights when nested.
<!-- Bad: ScrollView inside ScrollView -->
<ScrollView ...>
<LinearLayout ...>
<ScrollView ...>
<TextView android:text="Nested" />
</ScrollView>
</LinearLayout>
</ScrollView>
Remediation
Flatten the layout so that only one scrollable container exists, or use NestedScrollView with RecyclerView configured for nested scrolling via android:nestedScrollingEnabled. Alternatively, give inner lists a fixed height to prevent them from attempting to scroll.
<!-- Good: single scroll container -->
<ScrollView ...>
<LinearLayout android:orientation="vertical" ...>
<TextView android:text="Content" />
</LinearLayout>
</ScrollView>