how to change size of button dynamic in android

前端 未结 3 1112
无人及你
无人及你 2020-12-10 00:02

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

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 00:45

    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);
    

提交回复
热议问题