RecyclerView v23.2.0 和向上滑动后的空白 [英] RecyclerView v23.2.0 and blank space after swiping up

查看:37
本文介绍了RecyclerView v23.2.0 和向上滑动后的空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将支持库更新到 23.2.0.并将 recyclerView 的高度更改为 wrap_content,如博客 这里 :

I updated the support library to 23.2.0. and changed the height of the recyclerView to wrap_content as explained in the blog here :

RecyclerView 小部件为创建列表和网格以及支持动画提供了一个先进而灵活的基础.此版本为 LayoutManager API 带来了令人兴奋的新功能:自动测量!这允许 RecyclerView 根据其内容的大小调整自身大小.这意味着以前不可用的场景,例如将 WRAP_CONTENT 用于 RecyclerView 的维度,现在可以实现.您会发现所有内置的 LayoutManager 现在都支持自动测量.

The RecyclerView widget provides an advanced and flexible base for creating lists and grids as well as supporting animations. This release brings an exciting new feature to the LayoutManager API: auto-measurement! This allows a RecyclerView to size itself based on the size of its contents. This means that previously unavailable scenarios, such as using WRAP_CONTENT for a dimension of the RecyclerView, are now possible. You’ll find all built in LayoutManagers now support auto-measurement.

由于此更改,请务必仔细检查您的项目视图的布局参数:以前忽略的布局参数(例如滚动方向的 MATCH_PARENT)现在将得到完全尊重.

Due to this change, make sure to double check the layout parameters of your item views: previously ignored layout parameters (such as MATCH_PARENT in the scroll direction) will now be fully respected.

编辑/添加评论:我必须这样做,因为在更新match_parent"后,它做了它应该做的事情,它将卡片视图的高度拉伸到底部,所以我最终每页有一个卡片视图.

edited/added comment : I had to do this because after the update 'match_parent' did what it's supposed to do, it stretched the cardviews height down to the bottom, so I ended up having one cardview per page.

但是现在在向上滑动新创建的卡片视图之后,它们之间又出现了不需要的空间.

But now after swiping up the newly created cardviews have the unwanted space between them again.

让我进一步澄清:

  • 首次加载页面时,5 个卡片视图可见且显示正确.
  • 我向上滑动,一个新的卡片视图编号 6 出现
  • 进一步向上滑动使cardview 7号出现,但6号和7号之间有空格
  • 所有新创建的卡片视图之间都有一个巨大的空白区域

有人遇到过这种行为吗?

Has anyone encountered this behavior ?

推荐答案

我发现了错误.

在cardview所在的布局文件中,我不得不将周围的RelativeLayout的layout_height属性也修改为WRAP_CONTENT.

In the layout file where the cardview is in, I had to modify the surrounding RelativeLayout's layout_height attribute to WRAP_CONTENT as well.

有趣的是,我将 RecyclerView 的 layout_height 改回了 MATCH_PARENT,它仍然可以正常工作.

Interesting part is, I changed the layout_height of RecyclerView back to MATCH_PARENT and it still worked as desired.

这篇关于RecyclerView v23.2.0 和向上滑动后的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆