我有一个RecyclerView,它以缩略图的形式显示一堆图像。图像的width和height可能会有所不同,有些是1280x720,有些是4128x2322。
当我为XML布局中的ImageView选择scaleType="center"时,我的4128x2322图像可以完美地显示(它们如期占据整个屏幕),但是1280x720图像的显示方式非常糟糕(您看不到整个图像,只能看到其中的一部分,就像有人放大了一样)。
当我选择scaleType="centerInside"时,1280x720图像会完美地显示出来(整个图像都会显示出来,看起来就像是我们在YouTube等应用程序中看到的一个真正的缩略图),但是4128x2322图像缩小了,看起来不太好。
解决这个问题的典型方法是什么,以便我的ImageView可以根据width和height是什么,以最合适的方式调整它的width和height。
为了完整起见,下面是我的image_list_item.xml布局文件:
<layout 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">
<data>
<variable
name="image"
type="com.celik.abdullah.learningdifferentscaletypesforimageview.Image" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="100">
<FrameLayout
android:id="@+id/image_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:scaleType = "center">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="center"
tools:src="@mipmap/ic_launcher_round"
app:imageSrc="@{image.imageUrl}" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>ImageView被包装到一个FrameLayout中,因为我想稍后在它上面放一些图标。但这对这个问题并不重要。
发布于 2020-04-15 14:33:27
请在ImageView标签中添加android:scaleType="fitXY" ...
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
tools:src="@mipmap/ic_launcher_round"
app:imageSrc="@{image.imageUrl}" />https://stackoverflow.com/questions/61172907
复制相似问题