Search code examples
androidandroid-relativelayoutandroid-scrollview

ScrollView not scrolling when ScrollView as parent layout


I have a RelativeLayout inside ScrollView. But ScrollView not scrolling when it as parent layout.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent"

>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/iv_about_background"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:src="@drawable/stack" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/iv_about_background"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
       />
</RelativeLayout>
</ScrollView>

Edit: I removed rootView.setOnTouchListener from my fragment and ScrollView is working fine


Solution

  • Try with

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:fillViewport="false"
    android:layout_height="match_parent"
    
    >
    
        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
                    <ImageView
                        android:id="@+id/iv_about_background"
                        android:layout_width="match_parent"
                        android:layout_height="150dp"
                        android:src="@drawable/stack" />
    
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/iv_about_background"
                        android:paddingLeft="10dp"
                        android:paddingRight="10dp"
                       />
            </RelativeLayout>
    
        </LinearLayout>
    
    </ScrollView>