【发布时间】:2016-05-19 11:38:00
【问题描述】:
当我将RecyclerView 放入NestedScrollView 中时,onBindViewHolder 会调用所有行,比如说我有一个大小为 30 的列表,然后即使不滚动,也会一次调用所有 30 行的onBindViewHolder
RecyclerView list;
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
list.setLayoutManager(layoutManager);
layoutManager.setAutoMeasureEnabled(true);
list.setNestedScrollingEnabled(false);
list.addItemDecoration(new VerticalSpaceItemDecoration(5));
list.setAdapter(adapter);
我的xml是
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_views"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/info"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAlignment="center"
android:visibility="visible"
/>
但如果我删除 NestedScrollView 它可以正常工作。
【问题讨论】:
-
你有没有找到解决这个问题的办法,这肯定和NestedScrollView里面的RecylerView有关
-
这个问题有什么解决办法吗?面临同样的问题。
-
stackoverflow.com/a/37649336/1237141 答案也对我不起作用。
标签: android android-recyclerview nestedscrollview android-nestedscrollview