如何在android中更改按钮动态的大小

Atu*_*thi 2 android android-button

我尝试setWidth()和setheight()方法,但它不起作用

Fla*_*vio 12

尝试使用LayoutParams.例如

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


小智 10

对我而言,完美无缺:

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

    myButton.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)