如何解决如何在不损失图像质量的情况下完美地将图像放入图像视图中
我试图在 imageView
中完美地拟合图像,但是当我将 centerCrop
与 adjustViewBounds
一起使用时图像不适合,但是当我将 fitXY
与 {{1} 一起使用时图像完全适合 imageView 但现在图像质量变差了,我的 adjustViewBounds
imageView
和 height
是 width
是的,我也使用了 match_parent
但是没用
截图//目前我正在使用 fitCenter
和 centerCrop
这是我的代码
adjustViewBounds
对于那些想知道什么是布局 material_cardview_snipet 的人,这里是它的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical"
android:weightSum="5">
<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_marginEnd="5dp"
android:layout_weight="4"
app:shapeAppearanceOverlay="@style/RoundedCornerHome">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/imagePostHome"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:contentDescription="@string/todo"
app:shapeAppearanceOverlay="@style/RoundedCornerHome" />
<include
android:id="@+id/imagepost_buttons"
layout="@layout/imagepost_buttons" />
</FrameLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:background="@color/grey"
app:cardBackgroundColor="@color/grey"
app:shapeAppearanceOverlay="@style/RoundedCornerHome">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/material_cardview_snipet"
layout="@layout/material_cardview_snipet" />
</FrameLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
解决方法
您可以在 firebase 中调整图像大小,无需为其编码 https://firebase.google.com/products/extensions/storage-resize-images 您可以使用这个很酷的 firebase 扩展。它将上传到 Cloud Storage 的图像调整为指定大小,并可选择保留或删除原始图像。
它需要一个 blaze 计划,为此使用它的试用版,或者如果您是学生,您可以使用您的 .edu id 并从谷歌获取。
,如果您的图像尺寸我的意思是高度和宽度比例与您的图像视图不匹配高度和宽度比例滑动将使图像适合您的图像视图的中心,如果比例不匹配,则图像的一部分会被剪切'匹配。 如果您强制图像适合图像视图,即使比率不匹配,它也会被压缩以适合 x 轴或 y 轴。所以你的图片看起来不像原来的。
所以像这样使用你的图像视图属性 android:layout_width="match_parent" android:layout_height="wrap_content"
这里的宽度是固定的,高度将根据图像高度计算。
,如果您从服务器或什至从 drawable 获取图像,请使用 glide 库 将图像设置为图像视图。 Google 还recommends Glide library 来处理android 中的图像。 很容易快速理解。见Doc
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。