我有两种方法:
public View addNewLinearLayout(Context context) {
LinearLayout linearLayout = new LinearLayout(context);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
params.height = 120;
linearLayout.setLayoutParams(params);
linearLayout.setBackgroundColor(Color.RED);
linearLayout.setGravity(Gravity.TOP);
linearLayout.addView(buttonsGenerator(context));
return linearLayout;
}
public View buttonsGenerator(Context context){
ListView lst;
lst = new ListView(context);
Button button = new Button(context);
return lst;
}
在 addNewLinearLayout 中,我添加了要查看的布局。在buttonsGenerator 中,我想将一些按钮添加到列表中,并在我的布局中从addNewLinearLayout 中添加带有按钮的列表。我如何创建按钮列表并使用方法buttonGenerator将它们添加到线性?