如何防止RecyclerView中项目的大小调整

huangapple go评论73阅读模式
英文:

how to prevent resizing of items in recyclerview

问题

我有一个异构的RecyclerView(图像、视频和文本),它运行良好,但问题是当我滚动时,它会根据帖子的高度进行调整大小。那么,我该如何使它像Instagram一样,在Instagram中快速滚动时,即使帖子尚未加载,它们也已经占据了它们的高度,不会重新调整大小。提前感谢!

英文:

I have a heterogeneous recyclerview (Image, video and text) it is working fine but the problem is when i scroll, it resizes according to the height of posts. so how can i make it like instagram as when we rapidly scroll in instagram even though the posts are not loaded but they occupy their height already and not resize, thanks in advance!

答案1

得分: 1

请确保在您的ViewHolders中,当您的ViewHolder更改其大小以适应您传递给它的任何内容时,高度不设置为wrapContent。
我建议使用ConstraintLayout来创建更好的视图。
有关更多信息,请查看文档:
https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintLayout

英文:

make sure that on your ViewHolders height isn't set on wrapContent when it happened your viewHolder change its size to what ever you are passing to it
i recommend to use ConstraintLayout to make better views
see the docs for more info
https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintLayout

答案2

得分: 0

确保被回收的项目的父视图组的高度未设置为 android:layout_height="wrapContent"。

英文:

Make sure the parent view group of the item's height that recycled isn't set to

android:layout_height="wrapContent"

huangapple
  • 本文由 发表于 2020年8月6日 02:13:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63271184.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定