ScrollView not Scrolling - Android

41,055

Solution 1

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.

Solution 2

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.

Solution 3

I was able to solve it by adding (android:windowSoftInputMode="adjustResize|stateHidden") in the activity manifest, like below

<activity
            android:name=".ui.main.MainActivity"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustResize|stateHidden"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar">
        </activity> 

Solution 4

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>

Solution 5

You should set the height of LinearLayout (child of Scrollview) to wrap_content.

When the child is taller than the ScrollView, then android:fillViewport="true" attribute has no effect.

Share:
41,055
David
Author by

David

Updated on November 10, 2021

Comments

  • David
    David over 2 years

    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>
    
  • David
    David about 9 years
    I know that. But I want to set Layout weight for these layouts so i Have to use fillViewPort.
  • Vikas
    Vikas about 9 years
    @David may be you can try android:layout_height="wrap_content" for the imageview with id="imageView1"
  • Ankit
    Ankit about 7 years
    there is nothing to do with linear layout or table layout
  • Sold Out
    Sold Out about 6 years
    Nop does not help allways.. This is just one of apparently several problems with this element of ADT...
  • Sold Out
    Sold Out about 6 years
    Nop, I have many scrollViews and some of them work, som do not, invariantly on this parameter.