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