Home > database >  How to scroll whole page, Recyclerview inside of Scrollview
How to scroll whole page, Recyclerview inside of Scrollview

Time:06-23

i am trying to implement same structure in video but my activity not scrolling down. Recyclerview scrolls but i want to scroll whole page like in video

I am trying to do this one

My design

<ScrollView>
    
    <androidx.constraintlayout.widget.ConstraintLayout>
 
    ...
    ...
    ...
    
    
    <androidx.recyclerview.widget.RecyclerView
                android:id="@ id/x"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
    
    </androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>

I solved my problem with this example structure. Note: if you use ScrollView instead of NestedScrollView, components slide a bit different

Final result

<?xml version="1.0" encoding="utf-8"?>
<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:background="@color/base"
    android:clickable="true"
    android:orientation="vertical"
    tools:context=".Fragment.BasketFragment">

    <androidx.appcompat.widget.Toolbar
        android:id="@ id/tb_BasketFragment"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="@color/white"
        android:elevation="4dp"
        app:title="@string/title_basket"
        app:titleTextAppearance="@style/Toolbar.TitleText"
        app:titleTextColor="@color/black" />


    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:overScrollMode="never">

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

            <androidx.appcompat.widget.AppCompatButton
                android:id="@ id/acb_FragmentBasket"
                android:layout_width="match_parent"
                android:layout_height="42dp"
                android:layout_marginHorizontal="30dp"
                android:layout_marginTop="26dp"
                android:background="@drawable/custom_background_2"
                android:text="@string/continue_shopping"
                android:textAllCaps="false"
                android:textColor="@color/white"
                android:textSize="16sp"
                app:itemRippleColor="@null" />

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

        </LinearLayout>


    </androidx.core.widget.NestedScrollView>


</LinearLayout>

CodePudding user response:

add this attribute to your RecyclerView

android:nestedScrollingEnabled="false"

if it doesn't work, use NestedScrollView instead of ScrollView

CodePudding user response:

You need to set your RecyclerView height as wrap_content, and put all your xml of your activity inside a ScrollView to get the result that you want.

Your Xml should look like this :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content"
    android:fillViewport="true"
    >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@ id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:adjustViewBounds="true"
            tools:srcCompat="@tools:sample/backgrounds/scenic" />

        <!-- Your Ui Here: The ImageView is just for test -->

        <androidx.recyclerview.widget.RecyclerView
            android:id="@ id/x"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toBottomOf="@id/imageView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            tools:itemCount="100"
            />
        
    </androidx.constraintlayout.widget.ConstraintLayout>
    
</ScrollView>
  • Related