android - 带有 StaggeredGridLayoutManager 的 RecyclerView,图像从 Glide 加载

标签 android android-recyclerview android-glide staggered-gridview staggeredgridlayout

我在使用 StaggeredGridLayoutManager 显示 RecyclerView 时遇到问题,其项目包含 imageview 并且图像加载到 imageview 使用 glide。 我面临的问题是,在加载图像后,它们不会交错并且大小相等,两列之间也有很大的差距。如何改变图像的高度而不在列中留有间隙?

最佳答案

我遇到了同样的问题。对我有用的是为我的 ImageView 设置 android:adjustViewBounds="true"。我什至没有设置 scaleType。

这是我的布局文件 item.xml 的全部内容。

<?xml version="1.0" encoding="utf-8"?>
<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gif_image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorFiller"
    android:adjustViewBounds="true"/>

希望这对您有所帮助!

关于android - 带有 StaggeredGridLayoutManager 的 RecyclerView,图像从 Glide 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36149213/

相关文章:

java - 使用自定义字体时出现问题 - "native typeface cannot be made"

android - 如何防止 Prismatic Joint 重置为初始交易限额?

android - 通过覆盖滑动调整图像大小不会调整图像大小

android - Glide库支持exif旋转

java - Android HttpClient cookie

安卓 WebView : weird rendering of 1px lines on hdpi screens

android - 使用 RecyclerView 和 GridLayoutManager 的简单 Android 网格示例(如旧的 GridView)

java - Android MVVM RecyclerView ClickListener Kotlin 到 Java 转换

android - Android:如何像YouTube一样创建ScrollView?

android - 与 Glide 一起使用的调色板有时无法加载深色鲜艳的颜色