Home > Blockchain >  Scrolling the whole view with a ListView insida a ScrollView
Scrolling the whole view with a ListView insida a ScrollView

Time:09-17

I'm making an app and I can't find any solutions.Here is my code:

<?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"
    tools:context=".MainActivity"
    android:background="@color/DarkGray"
    android:orientation="vertical">

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

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/BackGroundColor"
                android:orientation="horizontal"
                android:paddingTop="4dp"
                android:paddingBottom="4dp">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textAlignment="center"
                    android:textAllCaps="true"
                    android:textColor="@color/SecondaryTextColor"
                    android:textSize="18sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textAlignment="center"
                    android:textAllCaps="true"
                    android:textColor="@color/SecondaryTextColor"
                    android:textSize="18sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <androidx.recyclerview.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="400dp"
                android:background="@color/BlueGray"
                android:nestedScrollingEnabled="false"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/BackGroundColor"
                android:padding="4dp"
                android:textAlignment="center"
                android:textColor="@color/PrimaryTextColor"
                android:textSize="22sp" />

            <ListView
                android:id="@ id/eventsListView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="2dp"/>

        </LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>

What I'm trying to achive is add CardViews inside my ListView and be able to scroll not just the ListView but the whole view. I tried RecyclerView before but that didn't work for me either.

Here's my idea:

enter image description here

and Scroll the whole thing not just the ListView.

CodePudding user response:

You need to use NestedScrollView.

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.

Please refer NestedScrollView documentation

Don't forget to add recyclerView.setNestedScrollingEnabled(false); to your RecyclerView.

  • Related