how to change size of button dynamic in android

前端 未结 3 1102
无人及你
无人及你 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);
    
    0 讨论(0)
  • 2020-12-10 00:54

    Try using LayoutParams. For example

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

    0 讨论(0)
  • 2020-12-10 00:54

    For me works perfect this:

        ViewGroup.LayoutParams params = myButton.getLayoutParams();
        //Button new width
        params.width = 400;
    
        myButton.setLayoutParams(params);
    
    0 讨论(0)
提交回复
热议问题