How to Change size of ImageView Dynamically?

纵然是瞬间 提交于 2019-12-13 07:39:16

问题


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.


回答1:


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




回答2:


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.




回答3:


OK I found the Solution

Resizing an ImageView within a TableLayout programmatically




回答4:


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.



来源:https://stackoverflow.com/questions/6124413/how-to-change-size-of-imageview-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!