Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: resizing an ImageView in the XML

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?

like image 524
Mark Manickaraj Avatar asked Jun 07 '11 15:06

Mark Manickaraj


People also ask

How do I change the size of an image in xml?

This example demonstrate about How to resize Image in Android App. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


1 Answers

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".

like image 104
ameyume Avatar answered Oct 14 '22 20:10

ameyume