Reputation: 1
For Android, How can I change the image size in an ImageView in a layout?
My image is jpeg
format.
Upvotes: 9
Views: 48440
Reputation: 34360
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);
Upvotes: 5
Reputation: 12523
<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.
Upvotes: 11
Reputation: 39758
There are a few ways to change the size of an image in an imageView in XML.
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).
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.
Simply adjust the weight and height in the imageView (as others have mentioned).
Upvotes: 2
Reputation: 16354
<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)
Upvotes: 1