NestedScrollView陷入了recyclerview的困境

问题描述 投票:0回答:2

我正在使用NestedScrollView,我有3个recyclerviews。我正在解析json并在recyclerview中设置数据,现在的问题是,在我上一次的recyclerview中我设置了分页功能,所以直到没有为该recyclerview获取数据,我的整个屏幕卡住并冻结。我为此尝试了不同的解决方案。但它不起作用,我发现结果没有变化。任何人都可以帮助我吗?

XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    android:background="#f0f0f0"
    >

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

        <include layout="@layout/reseller_home_title" />

        <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/swiperefresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/bodyScroller"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:descendantFocusability="blocksDescendants"
                android:fillViewport="true"
                android:background="#f0f0f0"
                android:scrollbars="vertical">

                <LinearLayout
                    android:id="@+id/llFragment"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:descendantFocusability="blocksDescendants"
                    android:orientation="vertical">


                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@color/white">

                        <RelativeLayout
                            android:id="@+id/temp_orange_view"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@color/colorAccent"
                            />

                        <com.youth.banner.Banner
                            android:id="@+id/banner"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginRight="@dimen/_10sdp"
                            android:layout_marginLeft="@dimen/_10sdp"
                            android:layout_marginTop="@dimen/_10sdp"
                            app:indicator_drawable_selected="@drawable/library_module_bg_style_main_radious"
                            app:indicator_height="5dp"
                            app:indicator_width="5dp" />

                    </RelativeLayout>

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recyclerViewCategoryData"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:descendantFocusability="blocksDescendants"
                        android:isScrollContainer="false"
                        android:background="@color/white"
                        android:nestedScrollingEnabled="false"
                        android:paddingTop="@dimen/_10sdp" />

                    <LinearLayout
                        android:id="@+id/resellerPromotionBannerLayout"
                        android:layout_width="match_parent"
                        android:layout_height="80dp"
                        android:weightSum="2"
                        android:orientation="horizontal"
                        android:background="#f0f0f0"
                        android:layout_marginTop="@dimen/_10sdp"
                        >
                        <ImageView
                            android:id="@+id/iv_top_left_pro"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            />
                        <ImageView
                            android:id="@+id/iv_top_right_pro"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            />
                    </LinearLayout>
                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recyclerViewGroupData"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:descendantFocusability="blocksDescendants"
                        android:isScrollContainer="false"
                        android:nestedScrollingEnabled="false"
                        />

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recyclerViewGroupProductData"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#f0f0f0"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior"
                        android:descendantFocusability="blocksDescendants"
                        android:isScrollContainer="false"
                        android:nestedScrollingEnabled="false"
                        />

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#f0f0f0"
                        android:layout_marginTop="@dimen/_5sdp"
                        >
                        <TextView
                            android:id="@+id/tv_size_text"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="THEY'RE ALL SELLING THIS"
                            android:layout_centerHorizontal="true"
                            android:textStyle="bold"
                            android:textColor="@color/colorBlack"
                            android:textSize="16dp" />
                    </RelativeLayout>

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recyclerViewHpEntryData"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:descendantFocusability="blocksDescendants"
                        android:isScrollContainer="false"
                        android:background="#f0f0f0"
                        android:layout_marginTop="@dimen/_5sdp"
                        android:nestedScrollingEnabled="false"
                        >

                    </android.support.v7.widget.RecyclerView>

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/_15sdp"
                        android:background="#f0f0f0"
                        android:layout_marginTop="@dimen/_5sdp"
                        >
                        <ProgressBar
                            android:id="@+id/reseller_promotion_view_progress"
                            style="@style/Widget.AppCompat.ProgressBar.Horizontal"
                            android:layout_width="60dp"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:indeterminate="false"
                            android:max="100"
                            android:progress="20"
                            android:maxHeight="3dip"
                            android:minHeight="3dip"
                            android:progressDrawable="@drawable/resellerpromotion_progress" />
                    </RelativeLayout>

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recyclerViewProductData"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#f0f0f0"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior"
                        android:descendantFocusability="blocksDescendants"
                        android:isScrollContainer="false"
                        />


                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="40dp">
                        <ProgressBar
                            android:id="@+id/progressBar1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:visibility="gone"
                            android:layout_centerInParent="true" />
                    </RelativeLayout>



                </LinearLayout>
            </android.support.v4.widget.NestedScrollView>

        </android.support.v4.widget.SwipeRefreshLayout>


    </LinearLayout>

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

    <include layout="@layout/error_layout"
        />

</android.support.design.widget.CoordinatorLayout>
android android-recyclerview android-nestedscrollview
2个回答
0
投票

在你的RecyclerView中运行每个NestedScrollView的代码

ViewCompat.setNestedScrollingEnabled(recyclerView, false);

0
投票

试试这段代码吧,效果很好,

rvCompanies.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
rvCompanies.setLayoutManager(layoutManager);
rvCompanies.setNestedScrollingEnabled(false); // important
© www.soinside.com 2019 - 2024. All rights reserved.