1.Dies ist mein Code, wo ich versuche, eine Matrix von Schaltflächen mit Hilfe von Tabellenlayout anzuzeigen. Und ich habe auch versucht, diese Matrix Bildschirm unabhängig zu machen, aber das funktioniert nicht richtig. Im großen Emulator gibt es Problemtasten, die sich überlappen.Wie Sie den Tabellenlayout-Bildschirm unabhängig machen
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);
}
}
+1 für Gridlayout. –
@PareshMayani Danke Paresh als ich Anfänger Ihre Lösung half mir viel – pragati