【问题标题】:Android image change image dimensions according to device screen sizeAndroid图像根据设备屏幕尺寸更改图像尺寸
【发布时间】:2019-08-21 13:13:04
【问题描述】:

我有一个imageView,其宽度为"match_parent"(每端都有一些边距)。

由于不同的设备具有不同的宽度,因此图像不会填充 imageView,而是会在每一端留下一些间隙,具体取决于我在哪个设备上查看它。

我尝试过android:adjustViewBounds="true",但这会拉伸图像以填充宽度,从而严重扭曲内容。

什么是正确的方法?我应该给android多个不同尺寸的图像副本(比如不同像素密度的多个可绘制文件夹)吗?

更新

尝试将 scaleType 设置为“fitXY”,但这仍在拉伸图像而不保持纵横比。

这是我的 xml:

<ImageView
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="110dp"
        android:scaleType="fitXY"
        android:src="@drawable/inner_map"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/header" />

如果这很重要的话,我已经将该图像的不同分辨率的多个副本插入到不同的可绘制文件夹中

【问题讨论】:

    标签: android imageview android-drawable


    【解决方案1】:
    <ImageView
        android:id="@id/img"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop" />
    

    https://developer.android.com/reference/android/widget/ImageView.ScaleType

    【讨论】:

    • 这仍在拉伸图像。
    • 尝试中心裁剪
    • 不,带 viewbound 的 fitcenter 不起作用,但 centercrop 在没有 view viewBounds 的情况下工作
    • 好吧,我几乎一无所知,因为我不知道您的图像有多大或多小,所以最好根据最可能的情况进行猜测:D
    • 太好了,接受答案,编辑到工作中...下次发布图像尺寸:D
    猜你喜欢
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 2015-02-28
    相关资源
    最近更新 更多