Android: resizing an ImageView in the XML

AndroidXmlImageview

Android Problem Overview


I have an image that is too big to fit on the screen, and I want it fairly small on screen. How do I change the size of the image through XML?

I tried:

<ImageView
android:id="@+id/image"
android:layout_width = "100dp"
android:layout_height= "100dp"
android:scaleType="center"
android:layout_gravity="center_horizontal|bottom"
android:src="@drawable/dashboard_rpm_bottom"
>
</ImageView>

But the image isn't resized... it gets cropped. Any ideas?

Android Solutions


Solution 1 - Android

for example:

<ImageView android:id="@+id/image_view"     
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:adjustViewBounds="true"  
  android:maxWidth="42dp"  
  android:maxHeight="42dp"  
  android:scaleType="fitCenter"  
  android:layout_marginLeft="3dp"  
  android:src="@drawable/icon"  
  /> 

Add property android:scaleType="fitCenter" and android:adjustViewBounds="true".

Solution 2 - Android

Mark,

I believe you want to use android:scaleType="fitXY".

Solution 3 - Android

Please try this one works for me:

<ImageView android:id="@+id/image_view"     
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:adjustViewBounds="true"  
  android:maxWidth="60dp" 
  android:layout_gravity="center" 
  android:maxHeight="60dp"  
  android:scaleType="fitCenter"  
  android:src="@drawable/icon"  
  /> 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMark ManickarajView Question on Stackoverflow
Solution 1 - AndroidameyumeView Answer on Stackoverflow
Solution 2 - AndroidWill TateView Answer on Stackoverflow
Solution 3 - AndroidAlok SinghView Answer on Stackoverflow