简体   繁体   中英

RecyclerView inside ViewPager inside NestedScrollView - doesn't work well

The problem is that the NestedScrollView is not scrolling when the RecyclerView has data.

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

   ...
<androidx.viewpager.widget.ViewPager
     android:id="@+id/vp_perfil"
     android:layout_width="match_parent"
     android:layout_height="600dp"
     android:background="#8E5252">
</androidx.viewpager.widget.ViewPager>

</androidx.core.widget.NestedScrollView>

It's like NestedScrollView is a normal layout and can't set ViewPager to wrap_content because it only works like match_parent .

Try like below snippet:

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

    <androidx.core.widget.NestedScrollView
        android:id="@+id/sv_top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/ll_product_detail_bottom"
        android:layout_alignParentTop="true"
        android:overScrollMode="never">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/padding_5">

            <androidx.viewpager.widget.ViewPager
                android:id="@+id/pd_pager"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true" />

            <com.viewpagerindicator.CirclePageIndicator
                android:id="@+id/pd_indicator"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:gravity="bottom"
                android:padding="@dimen/padding_10"
                app:centered="true"
                app:fillColor="@color/colorPrimary"
                app:pageColor="@android:color/darker_gray"
                app:snap="false" />
        </RelativeLayout>
    </androidx.core.widget.NestedScrollView>
</RelativeLayout>

Hope this may help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM