如何动态改变ImageView的大小?
我正在创建一个动态表,其行包含图像视图和文本视图。我的问题是这个 imageview 正在获取原始图像的完整大小,但我想更改 imageview 的大小。我使用了 setLayoutParams ,但没有效果。 作为替代方案,我还使用 textview 而不是 imageview 并将图像设置为 textview 的背景并使用 setWidth 和 setHeight 但它有同样的问题。 请帮助我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过 scaleType-属性?
查看 ImageView 类的
setMaxWidth
和setMaxHeight
方法:链接
Have you tried the scaleType-Attribute?
Check out the
setMaxWidth
andsetMaxHeight
-methods of the ImageView-class:Link
假设您的图像是可绘制资源,您可以使用 ScaleDrawable 代替,并使用 xml 属性
android:scaleHeight
和android:scaleWidth
缩小图像。Assuming your image is a drawable resource, you can use ScaleDrawable instead, and use the xml attributes
android:scaleHeight
andandroid:scaleWidth
to shrink your image.好的,我找到了解决方案
以编程方式调整 TableLayout 中的 ImageView 大小
OK I found the Solution
Resizing an ImageView within a TableLayout programmatically
尝试将布局文件中的 ImageView 的layout_width 和layout_height 更改为以sp 为单位测量的一些常量值,例如
100sp
。这将使所有 ImageView 看起来都一样。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.