【问题标题】:RecyclerView GridLayoutManager is showing extra margin top and bottomRecyclerView GridLayoutManager 显示顶部和底部的额外边距
【发布时间】:2020-12-28 22:48:14
【问题描述】:

我正在使用 Recycler View 和 GridLayoutManager,它在图像的顶部和底部显示边距,这就是我得到的:

onBindViewHolder:

    @Override
    public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
        Log.e(TAG, "in onBindViewHolder");
        Glide.with(mContext)
                .load(getUriFromMediaStore(position))
                .placeholder(new ColorDrawable(Color.LTGRAY))
                //.override(96, 96)
                .centerCrop()
                .into(holder.imageView);
    }

image_item.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/item_image"
        android:layout_width="136dp"
        android:layout_height="160dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:adjustViewBounds="true"
        android:contentDescription="@string/im" />
</RelativeLayout>

activity_image_picker.xml:

<androidx.recyclerview.widget.RecyclerView 
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/image_recycler_view"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context="com.example.myapplication.ImagePickerActivity" />

【问题讨论】:

    标签: android image android-recyclerview margin grid-layout


    【解决方案1】:

    只需在您的 ImageView

    中添加以下行
    android:scaleType="fitXY"
    

    您的图片将使用完整的高度和宽度。

    【讨论】: