Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, Change Image size in ImageView

For Android, How can I change the image size in an ImageView in a layout?

My image is jpeg format.

like image 895
LetsamrIt Avatar asked Aug 25 '12 16:08

LetsamrIt


People also ask

How do I change the size of a picture on my android?

Tap the image you want to adjust. You can adjust the size of an image or rotate it: Resize: Touch and drag the squares along the edges. Rotate: Touch and drag the circle attached to the image.

How set ImageView width and height dynamically in android?

If you want to just fit the image in image view you can use" wrap content" in height and width property with scale-type but if you want to set manually you have to use LayoutParams. Layoutparams is efficient for setting the layout height and width programmatically.

How do I stop my android from stretching photos?

You need to set the android:scaleType attribute on your image view. If the image is bigger than your view, either use centerInside or one of the fitXY , fitStart , fitEnd options. You have all the info you need on the Android developer documentation for the ImageView class.


4 Answers

<ImageView
    android:id="@+id/imageView1"
    android:layout_margin="20dp"
    android:src="@drawable/stop" 
    android:layout_width="50dp"
    android:layout_height="50dp"/>

Just change width and height attribute.

like image 199
s_bei Avatar answered Oct 15 '22 01:10

s_bei


You can also set Params using LayoutParams

ImageView yourImageView= (ImageView)findViewById(R.id.imageId);

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30);
//width and height of your Image ,if it is inside Relative change the LinearLayout to RelativeLayout.
    yourImageView.setLayoutParams(layoutParams);
like image 24
Zar E Ahmer Avatar answered Oct 15 '22 02:10

Zar E Ahmer


There are a few ways to change the size of an image in an imageView in XML.

  1. Scale the image by pulling around the edges of the imageView in the Graphical Layout (this is not really advised since the Graphical Layout sometimes adds undesired properties into the XML).

  2. Apply a weight to the imageView (this requires the parent object to have specified a weightSum), causing the image to scale according to the screen size. This seems to be the most reliable way to gauge how your layout will look on many different sized screens.

  3. Simply adjust the weight and height in the imageView (as others have mentioned).

like image 39
Scott Tesler Avatar answered Oct 15 '22 01:10

Scott Tesler


<ImageView
    android:id="@+id/imageViewId"
    android:src="@drawable/icon" 
    android:layout_width="xxdp"
    android:layout_height="yydp"/>

where xx is the width in pixels and yy is the height in pixels.

(give integer values as you desire the size to be)

like image 43
Swayam Avatar answered Oct 15 '22 01:10

Swayam