SetWidth () Android Button
I created a button placed in a RelativeLayout and I would like to set its size. But I can only set it to a larger size than the original one, for example I can resize it to 200dp but not 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
thank
+3
thomas-hiron
source
to share
2 answers
This is because it Button
has a minimum width by default 64dip
. Set before setting the width 0
.
b.setMinimumWidth(0);
+6
Matthias robbers
source
to share
you can set the width of the button by specifying values ββin the properties window of the xml.on design panel on the right side of the UI design. You can use a small button instead of a button to make it 20dpi.
0
Sharath
source
to share