【问题标题】:RecyclerView with Glide images needs to scroll along with the activity带有 Glide 图像的 RecyclerView 需要与活动一起滚动
【发布时间】:2018-04-10 00:42:19
【问题描述】:

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

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

根据RecyclerView need to scroll along the activity

现在 recyclerview 正在随着活动滚动,但现在还有另一个问题。并非所有图像都可见。看起来 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"

【问题讨论】:

  • 你能给我看看你的视图持有者 xml 吗?
  • 我已编辑问题
  • 你能给我看看项目的xml吗?我的意思是 xml inflate(R.layout.blalba)
  • 您可以尝试将android.support.constraint.ConstraintLayout 删除为Relative Layout,并且不要忘记删除您的xml 中的所有约束属性。

标签: android android-recyclerview android-glide


【解决方案1】:

更新:

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

【讨论】:

  • 它改变了图像的外观,但仍然没有显示所有图像。只有 3 张图像可见。当我打开滚动时,我可以看到所有图像,但我需要在这个活动滚动器中滚动它们,这对用户来说非常混乱。
  • 切换到 NestedScrollView 解决了这个问题,然后我只需要允许垂直滑块就可以了。谢谢
  • 滚动只有一个问题。到谷底的时候是平滑的,往上走的时候不是平滑的,滑动手指的时候不继续滚动,抬起手指的时候就停止了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-15
  • 1970-01-01
  • 1970-01-01
  • 2020-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多