带有 Glide 图片的 RecyclerView 需要随着 activity 一起滚动

RecyclerView with Glide images needs to scroll along with the activity

我有一个 activity,其中包括一些文本视图和一个带有 Glide 显示图像的 recyclerView。我有一个问题,recyclerview 有自己不需要的滚动条。

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

根据

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

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

这是我的回收视图

<?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);

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

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