【问题标题】:Update height of RecyclerView更新 RecyclerView 的高度
【发布时间】:2018-10-18 10:23:10
【问题描述】:

我有一个带有 ViewFlipper -> NestScrollview -> LinearLayout 的布局(两个 RecyclerViews 的父级)。两个 RV 的高度都设置为 wrap_content 和 setNestedScrollingEnable(false)。现在的问题是,只要其中一个 RV 对其适配器进行过滤,即使项目数量减少,它仍会保持其旧视图大小。如何使 RV 尺寸适应项目尺寸的新变化?当我将两个 RV 嵌套在 NestedScrollView 中时,我意识到这开始发生了。无论如何,在更新 RV 的内容时更新子视图大小。调用 notifyDataSetChanged() 不会更新视图大小

【问题讨论】:

  • 在嵌套滚动视图中拥有回收器视图不是一个好主意,而是尝试在回收器视图中拥有回收器视图
  • 这可能行得通。我将研究使用 getItemType 方法来加载另一个 recyclerView,因为我只需要垂直 RV 第一行的内部 RV。也许像 Google Play 商店之类的东西

标签: android android-recyclerview android-nestedscrollview


【解决方案1】:

如果每次过滤列表时都将 notifyDataSetChanged 放入适配器中,它应该可以工作。这是我的一个项目的示例,其中我根据 searchview 查询过滤列表,并且每次重新分配列表时,我都会在适配器中调用 notifyDataSetChanged()

 @Override
            protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
                if (!listFiltered.isEmpty()) {
                    listItems = (ArrayList<ListaConsultaFamilia>) filterResults.values;
                    notifyDataSetChanged();
                }
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    • 2019-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多