我正在尝试通过代码动态添加按钮。
但我坚持如何通过代码设置android:layout_width
按钮。0dp
尝试这个 :
LayoutParams lp = new LayoutParams(0, LayoutParams.WRAP_CONTENT);
myButton.setLayoutParams(lp);
进口,
import android.view.ViewGroup.LayoutParams;
谢谢
Your button have layoutParams. Get those params, update the width and reapply them:
ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams)myButton.getLayoutParams();
lp.width = 0;
myButton.setLayoutParams(lp);