android - 带有 Glide 图片的 RecyclerView 需要随着 Activity 一起滚动

标签 android android-recyclerview android-glide

我有一项 Activity ,其中包括一些 TextView 和一个使用 Glide 显示图像的 recyclerView。我遇到了一个问题,即 recyclerview 有自己不需要的滚动条。

然后我添加了这个:android:nestedScrollingEnabled="false"到 RecyclerView xml

根据 RecyclerView need to scroll along the activity

现在recyclerview是随着activity一起滚动的,但是现在又出现了一个问题。并非所有图像都可见。看起来 RecyclerView 在膨胀时不知道其中所有图像的大小。我正在使用 Glide 来显示图像,图像项的大小固定为 250dp。

如果我删除 nestedScrollingEnabled 属性,那么所有图像都可见,但我需要在该 recyclerView 内滚动。

这是我的回收 View

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_prikazi_vest"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin1"
        android:paddingRight="@dimen/activity_horizontal_margin1"
        android:paddingTop="@dimen/activity_horizontal_margin1"
        android:scrollbars="vertical"
        tools:context="myapp.app.news">

----------------here are some textviews----------------------


    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view_images"
        android:nestedScrollingEnabled="false"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:scrollbars="none"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    </android.support.constraint.ConstraintLayout>
</ScrollView>

这是我用于 Glide 的设置

RequestOptions options = new RequestOptions()
        .centerCrop()
        .placeholder(R.drawable.image1)
        .error(R.drawable.image2)
        .priority(Priority.HIGH);

更新:

要平滑滚动,请在 recyclerview 中使用它

android:nestedScrollingEnabled="false"
android:isScrollContainer="false"

最佳答案

更新:

ScrollView 更改为 android.support.v4.widget.NestedScrollView,并移除 android:nestedScrollingEnabled 属性。 NestedScrollView 是可以包含可滚动子项的布局。


一个选项是将 centerCrop() 更改为 fitCenter()

RequestOptions options = new RequestOptions()
    .fitCenter()
    .placeholder(R.drawable.image1)
    .error(R.drawable.image2)
    .priority(Priority.HIGH);

关于 Glide 选项的详细信息: https://github.com/bumptech/glide/wiki/Transformations

center crop fit center

关于centerCrop、fitCenter的详细信息 https://robots.thoughtbot.com/android-imageview-scaletype-a-visual-guide

关于android - 带有 Glide 图片的 RecyclerView 需要随着 Activity 一起滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49743595/

相关文章:

android - 向左/向右滑动 RecyclerView 的部分行

android - 是否有可能让 Android Glide 等待/重新加载保存在另一个线程中的图像?

android - 加载下一个新项目android时如何更新 ListView ?

android - 异步任务上的模态 HUD

java - android:如何将LinkedHashMap发送到不固定大小的URL

android - 指定的 child 已经有一个 parent ,RecyclerView

Android - 检测 RecyclerView 中的最后一个项目何时可见

android - Glide 4.4 java.lang.AbstractMethodError

android - 如何让 Glide 保持连接?

android - FCM Android - 空消息 ID