NestedScrollView陷入recyclerview

时间:2019-03-20 06:10:25

标签: android android-recyclerview android-nestedscrollview

我正在使用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>

2 个答案:

答案 0 :(得分:0)

RecyclerView中的每个NestedScrollView运行以下代码

ViewCompat.setNestedScrollingEnabled(recyclerView, false);

答案 1 :(得分:0)

尝试此代码,效果很好,

rvCompanies.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
rvCompanies.setLayoutManager(layoutManager);
rvCompanies.setNestedScrollingEnabled(false); // important