1.这是我的代码,我试图在表格布局的帮助下显示按钮矩阵。我也试图使这个矩阵屏幕独立,但这不能正常工作。在大尺寸模拟器中,它给出了问题按钮重叠。
TableLayout layout = new TableLayout (this);
layout.setStretchAllColumns(true);
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
layout.setLayoutParams( new TableLayout.LayoutParams(height,width) );
layout.setPadding(1,1,1,1);
for (int f=0; f<=3; f++)
{
TableRow tr = new TableRow(this);
for (int c=0; c<=3; c++)
{
Button b = new Button (this);
b.setText(""+f+c);
b.setTextSize(10.0f);
b.setTextColor(Color.rgb( 100, 200, 200));
tr.addView(b,30,30);
final float scale = getBaseContext().getResources().getDisplayMetrics().density;
int pixels = (int) (dps * scale + 0.5f);
b.setHeight(pixels);
b.setWidth(pixels);
} // for
layout.addView(tr);
} // for
super.setContentView(layout);
}
}