Skip to content Skip to sidebar Skip to footer

How To Change Size Of Button Dynamic In Android

I try setWidth() and setheight() method but it not work

Solution 1:

Try using LayoutParams. For example

button.setLayoutParams (new LayoutParams(50, LayoutParams.WRAP_CONTENT)

Solution 2:

For me works perfect this:

    ViewGroup.LayoutParams params = myButton.getLayoutParams();
    //Button new widthparams.width = 400;

    myButton.setLayoutParams(params);

Solution 3:

I found this to be the best solution because it also allows the button to be repositioned at the same time by simply changing its margin:

int buttonWidth = (int) (screenWidth / 3.0);
RelativeLayout.LayoutParams params = (LayoutParams) myButton.getLayoutParams();
params.width = buttonWidth;
params.leftMargin = buttonWidth;
myButton.setLayoutParams(params);

Post a Comment for "How To Change Size Of Button Dynamic In Android"