Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollView not scrolling at all

I can't make a ScrollView properly scrolling. It always cut off the content on the bottom, as if it were a normal LinearLayout.

My code

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"     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:isScrollContainer="true"         android:orientation="vertical" > 

Of course, I already tried to add / remove the "fillViewport" and "isScrollContainer" properties, and it did not change anything at all.

This is for ScrollView (VERTICAL ONLY)

HorizontalScrollView must be used for horizontal scrolling.

like image 628
thomaus Avatar asked Feb 11 '13 11:02

thomaus


People also ask

What is the difference between NestedScrollView and ScrollView?

NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.

How do I use horizontal ScrollView in react native?

In the ScrollView, we can scroll the components in both direction vertically and horizontally. By default, the ScrollView container scrolls its components and views in vertical. To scroll its components in horizontal, it uses the props horizontal: true (default, horizontal: false).


2 Answers

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> 
like image 199
thomaus Avatar answered Sep 24 '22 02:09

thomaus


❌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> 
like image 22
Sarang M K Avatar answered Sep 21 '22 02:09

Sarang M K