android – 在NestedScrollView onBindViewHolder中的RecyclerView调用所有getItemCount大小

当我将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它正常工作.

解决方法

高度问题引起的问题.

1)编辑nestedScrollView& RecyclerView如下:

<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′

相关文章

Android 通过adb shell命令查看内存,CPU,启动时间,电量等...
Monkey Android app稳定性测试工具之Monkey使用教程 by:授客...
Android 常见adb命令 by:授客 QQ:1033553122 1、 查看所有已...
这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...