NestedScrollView内部的RecyclerView一次触发所有onBindViewHolder

时间:2018-12-07 17:39:26

标签: android user-interface android-recyclerview android-nestedscrollview

我想使用 RecyclerView 作为其子级之一的可滚动屏幕,层次结构如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    ...
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        .../>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                .../>

            <FrameLayout
                .../>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/list_contacts"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clipToPadding="false"
                android:nestedScrollingEnabled="false"/>

            <FrameLayout
                .../>

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</LinearLayout>

请注意,RecyclerView的所有项目都应该可见,并且是 ImageView FrameLayout 等的同级

在当前解决方案中,有一个重大问题,所有项目都立即调用 onBindViewHolder ,但是我希望它们在屏幕上出现时像标准{{1 }}。我在做一些实验

RecyclerView

但是它毕竟失败了。

我知道解决方案之一是实现异构 recyclerView,但我想避免这样做。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

可能是因为在这种情况下,recyclerview无法知道自身的高度。 你可以尝试:

layoutManager.isAutoMeasureEnabled=true
相关问题