gpt4 book ai didi

android - RecyclerView item高度为wrap_content时向上滚动直接跳到顶部

转载 作者:行者123 更新时间:2023-11-29 19:11:43 25 4
gpt4 key购买 nike

这是xml文件

带有 RecyclerviewFragment:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list_photos"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.photos.PhotosFragment"
tools:listItem="@layout/card_photo">

</android.support.v7.widget.RecyclerView>

上面Recyclerview中每一项的布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
tools:src="@drawable/placeholder_photo_item" />

</android.support.v7.widget.CardView>

它看起来像这样:

item_height_wrap_content

如您所见,它不会在我滚动时加载得又快又流畅。它在某些项目上停止滚动。
同样,当我向上滚动时,它会直接跳到顶部。

下面是 RecyclerView 完美流畅快速的滚动效果,我可以通过制作 Recyclerview 的项目(这里是 CardView) 高度到 "match_parent"

item_height_match_parent

但这不是我希望列表的样子。该列表应该包含可变长度的图像,它们之间没有空格。

最佳答案

我正在使用 Glide 加载图像,并通过 Glide 添加占位符修复它:

GlideApp.with(mContext)
.load(url)
.placeholder(R.color.placeholder)
.into(holder.photo);

现在 RecyclerView 可以平滑滚动,不会跳转到向上滚动的第一个项目。

虽然它已经被修复了,但我真的不知道为什么 RecyclerView 会这样。

关于android - RecyclerView item高度为wrap_content时向上滚动直接跳到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45064069/

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