如何将随机大小的图像完美地拟合到随机大小的图像视图中

问题描述

您好,我正在尝试添加一个当前宽度为 match_parent 且高度为 0 dp 的图像视图,但我将来可以更改它

现在如何制作将从 Firebase 加载的图像使其完美适合图像视图有什么方法

顺便说一下,我现在正在使用中心裁剪,这很好,但没有太大帮助

这是我的 XML 代码

<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:layout_centerInParent="true"
    android:weightSum="5"
    android:orientation="vertical">

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/Card_View"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="5dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="5dp"
        android:layout_weight="4"
        app:shapeAppearanceOverlay="@style/RoundedCornerHome">

        <com.google.android.material.imageview.ShapeableImageView
            android:id="@+id/imagePostHome"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:adjustViewBounds="true"
            android:contentDescription="@string/todo"
            app:shapeAppearanceOverlay="@style/RoundedCornerHome" />

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

    <com.google.android.material.card.MaterialCardView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:cardBackgroundColor="@color/grey"
        android:layout_weight="1"
        android:layout_marginStart="5dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="5dp"
        android:background="@color/grey"
        app:shapeAppearanceOverlay="@style/RoundedCornerHome">


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


</LinearLayout>

这是从 firebase 加载图像的滑动代码

  Glide.with(mcontext)
                .load(uploadCurrent.getmImageUrl())
                .diskCacheStrategy(diskCacheStrategy.DATA)
                .placeholder(shimmerDrawable)
                .centerCrop()
                .into(holder.imageView);


    }

解决方法

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

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

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