安卓 - 毕加索 |占用额外空间的crop-square-transformation

问题描述

只是想在 android 的 RecyclerView 中创建一个类似 ui 的网格。

因此在片段中,将布局管理器设置为网格:

        binding.rvgallery.layoutManager = GridLayoutManager(requireContext(),3)
        galleryAdapter = galleryAdapter(this)
        binding.rvgallery.adapter = galleryAdapter

在适配器内部,我正在使用 Picasso 加载图像:

    private val squareTransformation = CropSquareTransformation()
            ...
            Picasso
                .get()
                .load(galleryItemList[position].name)
                .transform(squareTransformation)
                .into(holder.image)

这是我的相对项目 xml 布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/iv_item_gallery_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/default_gallery_item_content_description" />

</LinearLayout>

这是布局,回收视图所在的位置:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.galleryFragment">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_gallery"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

结果如下:https://www.youtube.com/watch?v=dXmfRfqc08g

  • 从 0.00 到 0.19,它只是加载图像,没有任何转换
  • 在那之后,它正在加载转换,但有一些额外的间距。我不想那样。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)