首页 > 解决方案 > android - 毕加索 | 裁剪平方变换占用额外空间

问题描述

只是想在android的RecyclerView中创建一个像ui这样的网格。

所以在片段中,将布局管理器设置为 grid :

        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>

这是布局,recycleview 所在的位置:

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

标签: androidxmlpicasso

解决方案


推荐阅读