微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 以编程方式调整图像按钮的边距,高度和宽度

我有一个imagebutton,其宽度和高度在xml文件中指定.但我想改变
这与屏幕尺寸的设备.
如何以编程方式设置 ImageButton的宽度,高度和边距?

解决方法

//ImageView Setup
ImageView imageView = new ImageView(this);

//setting height and width of imageview
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

//setting margins around imageimageview
params.setMargins(10,10,10); //left,top,right,bottom

//adding attributes to the imageview
imageView.setLayoutParams(params);

原文地址:https://www.jb51.cc/android/310395.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐