首页 > 解决方案 > 如何调整图像大小以正确适合卡片视图

问题描述

您好,我正在尝试将图像大小调整为卡片视图的大小,但有些图像适合,其中一些不希望所有图像都适合卡片视图

我已经使用了所有比例类型,但我发现最好的是中心裁剪,但使用后仍然有些图像不合适

这是XML代码

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

    <com.google.android.material.card.MaterialCardView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_centerInParent="true"
        android:layout_marginStart="1dp"
        android:layout_marginTop="11dp"
        android:layout_marginEnd="1dp"
        app:cardCornerRadius="13dp"
        app:cardElevation="1dp"
        app:cardMaxElevation="4dp">

        <com.google.android.material.imageview.ShapeableImageView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:contentDescription="@string/todo"
            android:scaleType="centerCrop"
            app:shapeAppearanceOverlay="@style/RoundedCorner" />

    </com.google.android.material.card.MaterialCardView>
</RelativeLayout>

标签: androidandroid-imageviewandroid-cardviewimage-resizing

解决方案


内卡视图使用:

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/todo"
            android:scaleType="centerCrop"
            app:shapeAppearanceOverlay="@style/RoundedCorner" />

推荐阅读