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 us开发者_JS百科ed 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.
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
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.
OK I found the Solution
Resizing an ImageView within a TableLayout programmatically
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.
精彩评论