0

I'm trying to use Scrollview but it is not working for me whatsoever.

<LinearLayout
    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:id="@+id/top"
    android:orientation="vertical"
    tools:context=".ui.home.HomeFragment">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        android:layout_marginTop="?attr/actionBarSize"
        android:fillViewport="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:orientation="vertical"
        android:weightSum="10">
      

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="20"
            android:columnCount="2"
            android:rowCount="3"
            android:alignmentMode="alignMargins"
            android:columnOrderPreserved="false"
            android:padding="15dp"
            >
            <androidx.cardview.widget.CardView
                .....
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_horizontal|center_vertical"
                    android:layout_marginTop="15dp"
                    android:orientation="vertical"
                    >
                    <TextView
                      ...>

                    </TextView>
                    <ImageView
                       ...>
                    </ImageView>
                </LinearLayout>
            </androidx.cardview.widget.CardView>

</GridLayout>

    </LinearLayout>
    </ScrollView>
</LinearLayout>

I tried every solution I found online, but nothing worked. I tried to add this : android:orientation="vertical" to the linearLayout, but it changed nothing. I still can't scroll How can I get the scrollView to work?

2
  • You probably meant to make the GridLayout's height wrap_content (and drop the weight - it's the only item). You're currently telling the LinearLayout to wrap the GridLayout, but the GridLayout is being told to use the LinearLayout's size, which is a circular dependency. Commented Feb 18, 2023 at 7:27
  • still not working Commented Feb 18, 2023 at 9:36

2 Answers 2

1

Put your layout under the ScrollView Like this

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ScrollActivity">

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

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/> <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </LinearLayout>

  </ScrollView>

Make sure that your Child layout has enough views so that can scrollable.

I hope this can helps you out from your problem ):

Sign up to request clarification or add additional context in comments.

Comments

0

Try replacing like this

android:layout_width="fill_parent"
android:layout_height="fill_parent"

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

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.