Recycler视图不滚动

时间:2018-02-24 11:28:18

标签: android android-recyclerview android-coordinatorlayout

我在ViewPager中有一个Recycler View,它位于NestedScroll View

我的布局如下

<CoordinatorLayout>
    <AppBarLayout>
        <CollapsingToolbarLayout>
            <Toolbar>
            </Toolbar>
        </CollapsingToolbarLayout>
    </AppBarLayout>
    <NestedScrollView>
        <ViewPager>
            <RecyclerView>
            </RecyclerView>
        </ViewPager>
    </NestedScrollView>
</CoordinatorLayout>

我在RecyclerView中有更多内容,但视图显示项目项目,直到滚动AppBarLayout。

如何使回收者视图滚动完整列表?

以下是View的屏幕截图 enter image description here enter image description here

编辑: 这是XML     

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="128dp">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="128dp"
            android:background="@color/colorPrimary">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="128dp"
                android:orientation="vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="64dp"
                    android:gravity="center"
                    android:textSize="32dp"
                    android:fontFamily="@font/amaranth"
                    android:text="@string/app_name" />
                <EditText
                    android:id="@+id/search_et"
                    android:layout_width="match_parent"
                    android:layout_height="59dp"
                    android:background="@drawable/rounded_corners"
                    android:layout_marginRight="14dp"
                    android:hint="Search"
                    android:maxLines="1"
                    android:inputType="text"
                    android:imeOptions="actionGo"
                    android:padding="10dp" />
            </LinearLayout>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
    android:id="@+id/nested_scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:fillViewport="true">

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_height="match_parent"/>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.CardView
    app:layout_anchor="@id/nested_scroll_view"
    app:layout_anchorGravity="bottom"
    android:id="@+id/card"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    app:cardElevation="1dp"
    app:cardMaxElevation="3dp">

    <android.support.design.widget.TabLayout

        android:id="@+id/tablayout"
        style="@style/MyCustomTabTextAppearance"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/whiteColor"
        app:tabGravity="fill"
        app:tabIndicatorColor="@color/tabBackgroundColor"
        app:tabMode="fixed">

    </android.support.design.widget.TabLayout>

</android.support.v7.widget.CardView>
</android.support.design.widget.CoordinatorLayout>

Java代码     searchResultsRecyclerView = v.findViewById(R.id.search_recycler_view);         searchResultsRecyclerView.setNestedScrollingEnabled(假);         searchResultsRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

    searchEditText = getActivity().findViewById(R.id.search_et);
    searchEditText.addTextChangedListener(new TextWatcher() {
        AsyncTask<Object, Object, Object> asyncTask;
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (asyncTask == null) {
                asyncTask = new SearchAsyncTask(editable.toString()).execute();
            } else {
                asyncTask.cancel(true);
                asyncTask = new SearchAsyncTask(editable.toString()).execute();
            }
        }
    });

2 个答案:

答案 0 :(得分:0)

使用recyclerview height wrap_content

<android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerView"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />

答案 1 :(得分:0)

在您的回收商视图xml

中添加此行

机器人:nestedScrollingEnabled =&#34;假&#34;