Voici mon xml:TableLayout pas centrage
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/test"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
>
<TextView
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<TextView
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</TableRow>
je produis le reste dynamique. À l'heure actuelle, il se centre horizontalement sur l'écran, mais tout est sur le côté gauche. Je sais que c'est une solution simple, mais je n'arrive pas à faire les choses correctement.
Voici mon code manuel:
for(Item l : leaders)
{
// Make a new row
TableRow row = new TableRow(this);
row.setBackgroundColor(Color.DKGRAY);
TextView name= new TextView(this);
TextView score = new TextView(this);
createView(row, name, l.getName());
createView(row, score, String.valueOf(l.getScore()));
name.setTextColor(Color.MAGENTA); // Just to distinguish between the columns
// Add row to table layout
tl.addView(row);
}
}
private void createView(TableRow row, TextView textView, String string)
{
textView.setText(string);
textView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
textView.setTextColor(Color.CYAN);
textView.setTextSize(32);
textView.setPadding(20, 0, 0, 0);
row.setPadding(0, 1, 0, 1);
row.addView(textView);
}
En outre, les réponses données n'a pas changé la mise en page.
1 pression = 1000 mots. –
Quand vous dites "ça le centre mais tout est à gauche" ça rend l'image difficile. Quel est le point que fait @paresh? Une capture d'écran serait très utile. –
Image l'écran du téléphone. Les lignes de la table sont alignées horizontalement mais sont alignées verticalement. – segFault