NestedScrollView onBindViewHolder中的RecyclerView调用所有getItemCount的大小 [英] RecyclerView inside NestedScrollView onBindViewHolder calling for all getItemCount size

查看:160
本文介绍了NestedScrollView onBindViewHolder中的RecyclerView调用所有getItemCount的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将RecyclerView放在NestedScrollView内时,onBindViewHolder要求所有行,例如说我的列表大小为30,那么即使没有滚动,一次也要为所有30行调用onBindViewHolder

When I put RecyclerView inside NestedScrollView then onBindViewHolder is calling for all row like say I have list which has size of 30 then onBindViewHolder is called for all 30 rows at one time even without scrolling

 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,它就可以正常工作.

but if I remove NestedScrollView it's working properly.

推荐答案

高度问题.

1)编辑NestedScrollView& RecyclerView如下:

1) Edit the NestedScrollView & RecyclerView as following:

 <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    ......
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
        .......
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_views"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ..... 
            />

2)确保已编译'com.android.support:recyclerview-v7:23.2.1'

这篇关于NestedScrollView onBindViewHolder中的RecyclerView调用所有getItemCount的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆