Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – Recyclerview同时绑定所有视图大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在另一个再循环视图(使用linearlayoutmanager)中有一个垂直回收器视图(带有GridLayoutManager).我现在遇到的问题是,内部的回收器视图(与GridLayoutManager)同时绑定所有的项目,甚至当前不在屏幕上的视图(onBindViewHolder()被调用它的所有项目).

为了给你更多的信息,在我的布局文件中,我把回收器视图的高度设为wrap_content.

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

任何想法如何解决

这是我的外部回收器视图的布局文件

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://scheR_685_11845@as.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>

这里是我内部回顾者视图的代码

<LinearLayout xmlns:android="http://scheR_685_11845@as.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 .:我正在使用这个适配器委托作为我的外部回收器视图:
https://github.com/sockeqwe/AdapterDelegates

解决方法

我认为嵌套的回收利用是一个非常糟糕的主意.当我尝试滚动,哪个回收器视图必须回应scolling,parrent或小孩.

这就是为什么我认为你在寻找ExpandableListView?这仅限于两个级别的列表,但这听起来像是为您的需要而工作).它也解决了问题的解决.

看起来像这样

编辑:甚至可以嵌套ExpandableListViews:

编辑:检查this lib水平扫描

大佬总结

以上是大佬教程为你收集整理的android – Recyclerview同时绑定所有视图全部内容,希望文章能够帮你解决android – Recyclerview同时绑定所有视图所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。