网格视图项目显示得太小:Java Android Studio

Grid View Items are displayed too small: Java Android Studio

我正在 java Android Studio 中实现网格视图,以将图库中的所有图像显示到其中。一切正常,但我的网格视图项目显示得非常小。列之间不必要地留有很多水平间距,这使得项目变小。这是我的 activity xml 具有网格视图的文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".ImportFromGallery">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.9">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.25">
            </RelativeLayout>

            <View
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="0.003"
                android:background="#e1e1e1" />

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.747">

                <GridView
                    android:id="@+id/galleryViewGridView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:numColumns="3"
                    android:stretchMode="columnWidth">
                </GridView>

            </RelativeLayout>

        </LinearLayout>

    </RelativeLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="0.003"
        android:background="#e1e1e1" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.097">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.8">
            </RelativeLayout>

            <View
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="0.003"
                android:background="#e1e1e1" />

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.197">
            </RelativeLayout>

        </LinearLayout>

    </RelativeLayout>

</LinearLayout>

这是我的 要在网格视图的每个项目中显示的图像视图:

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

    <ImageView
        android:id="@+id/gridGalleryImageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:scaleType="centerCrop"
        android:src="@mipmap/ic_launcher" />

</RelativeLayout>

这是我得到的输出:

-------------------------------------------- --------------------------------------------

这是我想要的输出:

这可能是什么问题。谢谢。

为您在网格视图项目中膨胀的图像视图使用以下代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:padding="3dp">

    <ImageView
        android:id="@+id/gridGalleryImageView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:scaleType="centerCrop"
        app:layout_constraintDimensionRatio="1:1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>