You can use ScaleType CENTER_INSIDE for this purpose. For more detail go through link. Android ImageView ScaleType
How can I show a photo in an imageview in its original aspect ratio?
-
20-07-2023 - |
Вопрос
I would like to show a photo from my phone in an ImageView. This photo is supposed to be shown in it's original aspect ratio. So it should fill up the whole width, but only use as much height as it needs due to it's ratio. In short: I want to show a photo in an imageview without scaling.
How can I do that? Right now I am using this layout. The problem is that it always scales the photo to fill up the whole screen.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/root"
android:orientation="vertical"
android:background="@android:color/black">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="center" />
</LinearLayout>
Решение
Другие советы
Try put image in drawable-nodpi
folder and set wrap_parent
for width and height in ImageView and set link to image in src
Try to set width to match parent, height to wrap content and to adjust view bounds:
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/drawable"/>
Не связан с StackOverflow