[英]How to fit image into the imageview perfectly without losing image quality android
我試着去完美契合圖像的imageView
,但圖像dosent合身當我使用centerCrop
與adjustViewBounds
但是當我使用fitXY
與adjustViewBounds
圖像完全適合於ImageView的,但現在的圖像質量得到最糟糕的,我的imageView
height
和width
都match_parent
是的,我也使用過fitCenter
但沒有用
截圖//目前即時通訊使用centerCrop
與adjustViewBounds
這是我的代碼
<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>
對於那些想知道什么是布局 material_cardview_snipet 的人,這里是它的代碼
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:layout_marginTop="5dp"
android:layout_marginEnd="25dp"
android:src="@drawable/ic_baseline_attach_money_24"
tools:ignore="RtlHardcoded"
android:contentDescription="@string/todo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Ian Somerhalder"
android:textColor="@color/white"
android:layout_marginTop="5dp"
android:textSize="20sp"
android:textStyle="bold"
tools:ignore="SmallSp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
tools:ignore="RtlHardcoded"
android:textSize="17sp"
android:layout_marginLeft="10dp"
android:textColor="@color/white"
android:text=".............."/>
</FrameLayout>
您可以在 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"
這里寬度是固定的,高度將根據圖像高度計算。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.