Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollView not Scrolling - Android

I am unable to scroll my scrollview. It has a textView, an imageview and few linear layouts inside of it. When I replace the imageview and linear layouts with textview it is working. Here is my code:

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

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

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

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Drop Text Down"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="555dp"
            android:src="@drawable/ic_launcher" />

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

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextView" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/ln"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:background="#000000"
            android:orientation="vertical" >

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

                <TextView
                    android:id="@+id/TextView06"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="TextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextView" />
            </LinearLayout>

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

                <TextView
                    android:id="@+id/TextView05"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="TextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextView" />
            </LinearLayout>

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

                <TextView
                    android:id="@+id/TextView04"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="TextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextView" />
            </LinearLayout>

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

                <TextView
                    android:id="@+id/TextView03"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="TextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextView" />
            </LinearLayout>

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

                <TextView
                    android:id="@+id/TextView02"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="TextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextView" />
            </LinearLayout>

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

                <TextView
                    android:id="@+id/TextView01"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="TextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextViewTextView" />
            </LinearLayout>

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

</LinearLayout>
like image 482
David Avatar asked May 17 '15 01:05

David


4 Answers

Maybe i'm too late for this, but the only method that helped me fix the scrollview not scrolling after hours of searching and trial and error method is, setting scrollview's height to 0dp.

Here's an example xml code for reference.

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
  • The top constraint layout having "match_parent" will fit the screen.
  • The Scroll View inside having "0dp" adjusts the height to the content inside and creates a scrollable view when the content goes beyond the top/ parent constraint layout.
  • The inner most constraint layout (child of scroll view) will contain the views and actual contents.
like image 174
rama-void Avatar answered Nov 15 '22 16:11

rama-void


Put an empty view with fixed height

<View
                android:layout_width="match_parent"
                android:layout_height="50dp" />

as your last item in the linear layout which is a child of scroll view..

This is just a trick, I don't know the logic. Maybe, in the presence of bottom navigation bar, the scrollview behaves like that. So if we add another view with height that matches the bottom navigation bar's height(40-50) it performs well.

like image 32
Akshatha Srinivas Avatar answered Nov 15 '22 16:11

Akshatha Srinivas


The child view of a ScrollView should be set to wrap_content. If you set it to match_parent, it will fill the area of the ScrollView and never scroll, because it won't be larger than the ScrollView.

Try changing the child LinearLayout layout_height to either wrap_content or a specific size (in dp) instead of match_parent.

like image 43
Bidhan Avatar answered Nov 15 '22 17:11

Bidhan


Your ScrollView child needs to have its height as wrap_content :

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

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

    ... 
    ...
</LinearLayout>
</ScrollView>
like image 43
Prashant Patel Avatar answered Nov 15 '22 15:11

Prashant Patel