我想在每行添加 3 个按钮,其中 ROW 是通过动态方式创建的。我尝试了以下方法,但它每行显示一个按钮。
LinearLayout ll_rootOBJ = findViewById(R.id.ll_root);
LinearLayout mainLayout = new LinearLayout(this);
mainLayout.setOrientation(LinearLayout.VERTICAL);
int total_items=13;
for (int k=0; k<total_items; k++)
{
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.HORIZONTAL);
ll.setTag(k);
Button b = new Button(this);
b.setTag(k);
b.setText("Button " + k);
ll.addView(b);
mainLayout.addView(ll);
}
ll_rootOBJ.addView(mainLayout);
任何帮助都会有用。谢谢。
最佳答案
只需在另一个 for 循环中向“LinearLayout ll” View 添加两个按钮即可
关于java - 如何在每行添加3个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52130585/