2

I am encountering an issue with the layout of an activity, where the content is not scrolling as intended. Currently, I have a Scrollview implemented within a ConstraintLayout, with a LinearLayout nested inside it. Despite attempting several approaches to resolve this problem, I have been unsuccessful in achieving the desired scrolling behavior.

At this point, I am seeking guidance and assistance in identifying a suitable solution for this issue. I have also experimented with placing the Scrollview within a LinearLayout, but unfortunately, this alternative approach did not yield the desired results either.

I would greatly appreciate any insights, recommendations, or assistance that can be provided to help address this matter effectively. Thank you for your attention and support!

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

    <ImageButton
        android:id="@+id/moreImageButton"
        android:layout_width="47dp"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center"
        android:background="#FFFFFF"
        android:clickable="true"
        android:minWidth="36dp"
        android:minHeight="36dp"
        android:src="@drawable/ic_menu_bar_black"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/imagebut"
        android:layout_width="49dp"
        android:layout_height="45dp"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center"
        android:background="#FFFFFF"
        android:clickable="true"
        android:minWidth="36dp"
        android:minHeight="36dp"
        android:src="@drawable/ic_icons8_plus"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TableRow
        android:id="@+id/hr2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#444"
        app:layout_constraintTop_toBottomOf="@+id/imagebut"
        ></TableRow>

    <TextView
        android:id="@+id/name_schedule"
        android:layout_width="411dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="5dp"
        android:background="#FFFFFF"
        android:fontFamily="serif"
        android:text="Schedule"
        android:textAlignment="viewStart"
        android:textColor="#000000"    
        android:textSize="25sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/hr2" />

    <TableRow
        android:id="@+id/hr1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#444"
        app:layout_constraintTop_toBottomOf="@+id/name_schedule"
        ></TableRow>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="5dp"
        android:layout_marginTop="10dp"
        android:animateLayoutChanges="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/hr1">

        <LinearLayout
            android:id="@+id/lly"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:animateLayoutChanges="true"
            android:scrollbars="vertical"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Monday"
                android:textColor="#000000"
                android:textSize="20sp" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_M"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Tuesday"
                android:textColor="#000000"
                android:textSize="20sp" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_T"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Wednesday"
                android:textColor="#000000"
                android:textSize="20sp" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_W"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Thursday"
                android:textColor="#000000"
                android:textSize="20sp"/>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_TH"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Friday"
                android:textColor="#000000"
                android:textSize="20sp"/>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_F"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Saturday"
                android:textColor="#000000"
                android:textSize="20sp"/>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_S"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView7"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Sunday"
                android:textColor="#000000"
                android:textSize="20sp"/>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_SU"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>
    </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
1

2 Answers 2

1

It is because scroller is as big as its child, the LinearLayout. Therefore, there is no need for the scroller to scroll. Try giving your scroller a definite height i.e. 500dp. Finally, the LinearLayout should be:

<LinearLayout
    android:id="@+id/lly"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ...
    >
Sign up to request clarification or add additional context in comments.

Comments

1

I have tried to change the height of RecyclerView(s) to 300dp. It works well

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

    <ImageButton
        android:id="@+id/moreImageButton"
        android:layout_width="47dp"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center"
        android:background="#FFFFFF"
        android:clickable="true"
        android:minWidth="36dp"
        android:minHeight="36dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/imagebut"
        android:layout_width="49dp"
        android:layout_height="45dp"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center"
        android:background="#FFFFFF"
        android:clickable="true"
        android:minWidth="36dp"
        android:minHeight="36dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TableRow
        android:id="@+id/hr2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#444"
        app:layout_constraintTop_toBottomOf="@+id/imagebut"
        ></TableRow>



    <TextView
        android:id="@+id/name_schedule"
        android:layout_width="411dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="5dp"
        android:background="#FFFFFF"
        android:fontFamily="serif"
        android:text="Schedule"
        android:textAlignment="viewStart"
        android:textColor="#000000"

        android:textSize="25sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/hr2" />

    <TableRow
        android:id="@+id/hr1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#444"
        app:layout_constraintTop_toBottomOf="@+id/name_schedule"
        ></TableRow>



    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="5dp"
        android:layout_marginTop="10dp"
        android:animateLayoutChanges="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/hr1">

        <LinearLayout
            android:id="@+id/lly"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:animateLayoutChanges="true"
            android:scrollbars="vertical"
            android:orientation="vertical">


            <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Monday"
                android:textColor="#000000"
                android:textSize="20sp" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_M"
                android:layout_width="match_parent"
                android:layout_height="300dp" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Tuesday"
                android:textColor="#000000"
                android:textSize="20sp" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_T"
                android:layout_width="match_parent"
                android:layout_height="300dp" />


            <TextView
                android:id="@+id/textView3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Wednesday"
                android:textColor="#000000"
                android:textSize="20sp" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_W"
                android:layout_width="match_parent"
                android:layout_height="300dp" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Thursday"
                android:textColor="#000000"
                android:textSize="20sp"/>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_TH"
                android:layout_width="match_parent"
                android:layout_height="300dp" />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Friday"
                android:textColor="#000000"
                android:textSize="20sp"/>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_F"
                android:layout_width="match_parent"
                android:layout_height="300dp" />


            <TextView
                android:id="@+id/textView6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Saturday"
                android:textColor="#000000"
                android:textSize="20sp"/>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_S"
                android:layout_width="match_parent"
                android:layout_height="300dp" />

            <TextView
                android:id="@+id/textView7"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:fontFamily="serif"
                android:text="Sunday"
                android:textColor="#000000"
                android:textSize="20sp"/>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_SU"
                android:layout_width="match_parent"
                android:layout_height="300dp" />


        </LinearLayout>

    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

The problem is the content of the ScrollView is not taller than the screen height. It cannot scroll.

You can have a look on the tutorial:

2 Comments

The reason why I wanted recycler view to wrap content is that, I also wanted to make it not scrollable and add many items whenever the user chose to add new tasks to days. That way I was hoping to have many non scrollable tasks under days and have the page itself scroll. Do you think I can use any other alternatives to recycler view for this case or would you recommend any other method to implement this idea?
I'm not sure I understand you user case. But I suggest that the ScrollView scroll by vertical and RecyclerView(s) should scroll by horizontal. You are able to use one RecyclerView with multiple types of item for displaying all child of the ScrollView. But it's harder than the current way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.