Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setWidth() Button Android

I've created a Button placed in a RelativeLayout and I'd like to set its size. But I can only set a larger size that the original one, for example I can resize it to 200dp but no to 20dp.

Is there a solution ?

Here is my code

Button b = new Button(getApplicationContext());
myLayout.addView(b);
b.setWidth(200); // Work
b.setWidth(20); // Don't work

Thanks

like image 315
thomas-hiron Avatar asked May 09 '26 21:05

thomas-hiron


1 Answers

That is because the Button has a minimum width of 64dip by default. Set it to 0 before setting the width.

b.setMinimumWidth(0);
like image 105
Matthias Robbers Avatar answered May 12 '26 11:05

Matthias Robbers