繁体   English   中英

NestedScrollView 中的 ViewPager 中的 RecyclerView - 效果不佳

[英]RecyclerView inside ViewPager inside NestedScrollView - doesn't work well

问题是当RecyclerView有数据时NestedScrollView不滚动。

<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>

这就像NestedScrollView是一个普通的布局,不能将ViewPager设置为wrap_content因为它只能像match_parent一样工作。

尝试像下面的片段:

<?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>

希望这可以帮助你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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