Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:layoutParams.setMargins()更改视图大小_Android - Fatal编程技术网

Android:layoutParams.setMargins()更改视图大小

Android:layoutParams.setMargins()更改视图大小,android,Android,我有一个按钮,我想改变的边缘。 这是我的密码: RelativeLayout.LayoutParams buttonParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); buttonParams.setMargins(r.getWidth() / 3 * 2, r.

我有一个按钮,我想改变的边缘。 这是我的密码:

 RelativeLayout.LayoutParams buttonParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                 buttonParams.setMargins(r.getWidth() / 3 * 2, r.getHeight() * 5 / 7, 0, 0);
                 b.setWidth(r.getWidth() / 4);
                 b.setHeight(r.getWidth() / 8);
                 b.setLayoutParams(buttonParams);

当我更改setMargins中的值时,b的大小会发生变化。为什么会出现这种情况?我该如何解决它?

我想这是因为你

   b.setWidth(r.getWidth() / 4); 
   b.setHeight(r.getWidth() / 8); 
在设置布局参数之前

将设置宽度和高度删除为b,以不更改其尺寸

干杯,