我有一个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, 10); //left, top, right, bottom
//adding attributes to the imageview
imageView.setLayoutParams(params);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句