azh*_*har 6 android android-layout
我有一个图像按钮,其宽度和高度在xml文件中指定.但我想用屏幕尺寸的设备更改它.
如何以编程方式设置ImageButton的宽度,高度和边距?
您好朋友,您可以通过以下代码设置
btnPlayVideo.getLayoutParams().height = XX;
btnPlayVideo.getLayoutParams().width = XX;
Run Code Online (Sandbox Code Playgroud)
或者看到这个图片按钮调整大小
//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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6368 次 |
| 最近记录: |