Arun Badole
Arun Badole

Reputation: 11097

How to Change size of ImageView Dynamically?

I am creating a dynamic table whose rows contains a imageview and a textview. My problem is this imageview is taking full size of original image but I want to change the size of imageview.I have used setLayoutParams which has no effect. As an alternative I also used textview instead of imageview and set image as textview's background and used setWidth and setHeight but it has the same problem. Plz Help Me.

Upvotes: 1

Views: 17616

Answers (4)

Egor
Egor

Reputation: 40218

Try changing your ImageView's layout_width and layout_height inside the layout file to some constant values measured in sp, for example 100sp. This will make all ImageViews look the same.

Upvotes: 0

Lukas Knuth
Lukas Knuth

Reputation: 25755

Have you tried the scaleType-Attribute?


Check out the setMaxWidth and setMaxHeight-methods of the ImageView-class:

To set an image to be a maximum of 100 x 100 while preserving the original aspect ratio, do the following: 1) set adjustViewBounds to true 2) set maxWidth and maxHeight to 100 3) set the height and width layout params to WRAP_CONTENT.

Link

Upvotes: 3

Arun Badole
Arun Badole

Reputation: 11097

OK I found the Solution

Resizing an ImageView within a TableLayout programmatically

Upvotes: 0

Phil
Phil

Reputation: 36289

Assuming your image is a drawable resource, you can use ScaleDrawable instead, and use the xml attributes android:scaleHeight and android:scaleWidth to shrink your image.

Upvotes: 1

Related Questions