gpt4 book ai didi

android - Recyclerview 同时绑定(bind)所有 View

转载 作者:IT老高 更新时间:2023-10-28 23:35:37 26 4
gpt4 key购买 nike

我在另一个recyclerview(带有LinearLayoutManager)中有一个垂直recyclerview(带有GridLayoutManager)。我现在面临的问题是,内部 recyclerview(带有 GridLayoutManager)同时绑定(bind)了它的所有项目,即使是目前不在屏幕上的 View (onBindViewHolder()为其所有项目调用)。

为了提供更多信息,在我的布局文件中,我将回收站 View 的高度设置为 wrap_content

我认为问题在于,由于有 2 个垂直嵌套的 recyclerviews,当父 RV 想要测量其子节点而子节点是另一个 RV 时,在 onMeasure() 中它会计算所需的大小整个 RV,而不仅仅是它要在屏幕上绑定(bind)的部分。

知道如何解决这个问题吗?

这是我的外部 recyclerview 的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/component_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</FrameLayout>

这是我的内部 recyclerview 的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/gutter"
android:paddingBottom="@dimen/gutter">

<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/gutter"
android:textSize="30sp"
android:textColor="@android:color/white"
android:fontFamily="sans-serif-thin"/>

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

</LinearLayout>

P.S.:我将这个适配器委托(delegate)用于我的外部 recyclerview: https://github.com/sockeqwe/AdapterDelegates

最佳答案

我认为嵌套的 recyclerviews 是一个非常糟糕的主意。当我尝试滚动时,哪个 recyclerview 必须响应 scolling、parrent 或 child。

这就是为什么我认为您正在寻找 ExpandableListView ?这仅限于两个级别的列表,但听起来它可以满足您的需求)。也解决了soling问题。

看起来像这样:

enter image description here

编辑:甚至嵌套的 ExpandableListViews 也是可能的:

enter image description here

编辑:检查 this用于水平滚动的库

关于android - Recyclerview 同时绑定(bind)所有 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38512278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com