首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何选择ImageView的scaleType

如何选择ImageView的scaleType
EN

Stack Overflow用户
提问于 2020-04-12 22:23:16
回答 1查看 118关注 0票数 0

我有一个RecyclerView,它以缩略图的形式显示一堆图像。图像的widthheight可能会有所不同,有些是1280x720,有些是4128x2322

当我为XML布局中的ImageView选择scaleType="center"时,我的4128x2322图像可以完美地显示(它们如期占据整个屏幕),但是1280x720图像的显示方式非常糟糕(您看不到整个图像,只能看到其中的一部分,就像有人放大了一样)。

当我选择scaleType="centerInside"时,1280x720图像会完美地显示出来(整个图像都会显示出来,看起来就像是我们在YouTube等应用程序中看到的一个真正的缩略图),但是4128x2322图像缩小了,看起来不太好。

解决这个问题的典型方法是什么,以便我的ImageView可以根据widthheight是什么,以最合适的方式调整它的widthheight

为了完整起见,下面是我的image_list_item.xml布局文件:

代码语言:javascript
复制
<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中,因为我想稍后在它上面放一些图标。但这对这个问题并不重要。

EN

回答 1

Stack Overflow用户

发布于 2020-04-15 14:33:27

请在ImageView标签中添加android:scaleType="fitXY" ...

代码语言:javascript
复制
               <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}" />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61172907

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档