简体   繁体   中英

Android image change image dimensions according to device screen size

I have an imageView whos width is "match_parent" (with some margins at each end).

Since different devices have different widths, the image is not filling the imageView but is leaving some gap at each end depending on which device am I viewing it on.

I have tried android:adjustViewBounds="true" but this stretches the image to fill the width which distorts the content badly.

what is the correct way? should I give android multiple copies of the image with different dimensions (like the multiple drawable folders for different pixel densities) ?

update

tried scaleType to "fitXY" but this is still stretching the image not keeping aspect ratio.

this is my 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" />

I have inserted multiple copies with different resolutions of this image into the different drawable folders if this is of any importance

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM