Shobhit Tewari
Shobhit Tewari

Reputation: 535

ScrollView not scrolling all items present in android

I am having a list of 31 items with each item having 4 textViews. I am wrapping all text views in a linear layout. I have shown 1 in the code. Just like that one, I have 30 more of this:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="loren"
            android:textColor="#000"
            android:gravity="center"
            android:textSize="20dp"
            android:layout_weight="10"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="5"
            android:textColor="#000"
            android:gravity="center"
            android:textSize="20dp"
            android:layout_weight="2"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="25"
            android:textColor="#000"
            android:gravity="center"
            android:textSize="20dp"
            android:layout_weight="2"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="9"
            android:textColor="#000"
            android:gravity="center"
            android:textSize="20dp"
            android:layout_weight="2"/>
    </LinearLayout>

and resultant code with only one shown for clarity.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fragment_globe"
    android:background="@color/dashBackground">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:orientation="horizontal">
                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:text="loren"
                        android:textColor="#000"
                        android:gravity="center"
                        android:textSize="20dp"
                        android:layout_weight="10"/>

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:text="5"
                        android:textColor="#000"
                        android:gravity="center"
                        android:textSize="20dp"
                        android:layout_weight="2"/>

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:text="25"
                        android:textColor="#000"
                        android:gravity="center"
                        android:textSize="20dp"
                        android:layout_weight="2"/>

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:text="9"
                        android:textColor="#000"
                        android:gravity="center"
                        android:textSize="20dp"
                        android:layout_weight="2"/>
                </LinearLayout>

            </LinearLayout>


    </ScrollView>


</androidx.constraintlayout.widget.ConstraintLayout>

I am not able to scroll all the items or all the linear layouts. I am able to scroll to some point but then it stops scrolling more downwards. I am new to android please help me.

Upvotes: 0

Views: 253

Answers (3)

DevHyperCoder
DevHyperCoder

Reputation: 943

Add these two attributes in ScrollView:

android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"

Upvotes: 1

Prajwal Waingankar
Prajwal Waingankar

Reputation: 2728

Use this:

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"   //set this to wrap
        android:fillViewport="true"   //set fillviewport to true.
        android:orientation="vertical">  

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"  //set this to match parent.
                android:orientation="vertical">

You need to set the height of scroll view to wrap and the LinearLayout which is the child of the ScrollView height to match_parent. Also, set the viewport to true.

Upvotes: 2

Jaimil Patel
Jaimil Patel

Reputation: 1347

Please add android:fillViewport="true" and android:scrollbars="vertical" in ScrollView Tag...

Upvotes: 1

Related Questions