gpt4 book ai didi

java - 如何调整按钮数组中按钮的大小

转载 作者:行者123 更新时间:2023-12-01 04:33:05 24 4
gpt4 key购买 nike

我正在尝试调整我制作的按钮数组中的按钮大小,但我不知道如何调整

这是我的代码

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
final TableLayout container = (TableLayout) findViewById(R.id.tableLayout5);

Button btn[][] = new Button[10][10];

for(int i = 0; i<10; i++){
for(int j = 0; j<10; j++){
btn [i][j] = new Button(this);


container.addView(btn[i][j],i);

}

}

}

最佳答案

我不知道你是否知道,但这将创建 100 个按钮,无论如何:可以这样做

public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(width_of_button , height_of_button);
final TableLayout container = (TableLayout) findViewById(R.id.tableLayout5);

Button btn[][] = new Button[10][10];

for(int i = 0; i<10; i++){
for(int j = 0; j<10; j++){
btn [i][j] = new Button(this);
btn.setText("Button "+i+":"+j); // if you need to trace which is which



container.addView(btn[i][j],i,lp);// add button with specified dims

}

关于java - 如何调整按钮数组中按钮的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17736419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com