我想以编程方式添加一个按钮,应该设置哪些LayoutParams。 不幸的是,应用程序出现异常:
java.lang.NullPointerException:尝试在null对象引用上写入字段'int android.view.ViewGroup $ LayoutParams.height'
我不知道原因。你能帮我吗? 这是我的代码。
Button b = new Button(getApplicationContext());
b.setText(R.string.klick);
ViewGroup.LayoutParams params = b.getLayoutParams();
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;