ScrollView not scrolling at all

Answer: the ScrollView is not working when used as the root element of an XML layout. It has to be wrapped inside a LinearLayout.

Solution then :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true" >

        <LinearLayout android:id="@+id/scroll_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

        </LinearLayout>
    </ScrollView>
</LinearLayout>

❌Tried all the above mentioned answers, but still my issue was unsolved. And after some debugging and changes, my issue got fixed that is the ScrollView is getting scrolled.

  • We need not to add any parent element to the ScrollView to make it scroll (as mentioned in some of the other answers here).

✔️The Fix was for my issue✔️

  • changed the height of the ScrollView to 0dp

    android:layout_height="0dp"

  • Constrained the Top and Bottom to parent/respective views/elements

    app:layout_constraintTop_toBottomOf="@+id/imageView4" app:layout_constraintBottom_toBottomOf="parent"

The final xml looks like this

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintTop_toBottomOf="@+id/imageView4"
    app:layout_constraintBottom_toBottomOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

           <!-- Loong content -->

    </LinearLayout>
</ScrollView>

Scroll View as Parent has no issues. I faced such issue when we add padding/margin to the direct child of scrollview. Keep the child of scrollview with just height and width properties, den it will work fine.

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        android:fillViewport="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:animateLayoutChanges="true"
            android:orientation="vertical">
</LinearLayout>
</ScrollView>

The selected answer IS NOT CORRECT!

You CAN use ScrollView as the root view, it doesnt work for you because you are missing the padding.

Add something like:

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"