我制作了一个10x10的电路板,但可视化为我提供了矩形。我想知道如何创建正方形,使高度等于宽度。有人可以帮忙吗?
Java代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
chronometer = (Chronometer)findViewById(R.id.chronometer);
tableLayout = (TableLayout) findViewById(R.id.tabuleiro);
GradientDrawable gd = new GradientDrawable();
gd.setStroke(1, 0xFF000000);
gd.setColor(Color.rgb(0, 0, 128));
final GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setStroke(1, 0xFF000000);
gradientDrawable.setColor(Color.RED);
TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT);
TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
tableLayout = (TableLayout) findViewById(R.id.tabuleiro);
for (int i = 0; i < tamanho_tabuleiro; i++){
tableRow= new TableRow(this);
tableRow.setLayoutParams(rowParams);
for (int j = 0; j < tamanho_tabuleiro; j++) {
textView = new TextView(this);
textView.setBackgroundDrawable(gd);
textView.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.setBackgroundDrawable(gradientDrawable);
}
});
tableRow.addView(textView);
}
tableLayout.addView(tableRow, tableParams);
&#13;