Je tente de placer la barre de défilement (verticale et horizontale) pour la disposition de la table.Barre de défilement pour TableLayout
Voici mon xml:
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40"
android:fillViewport="true">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<TableLayout
android:id="@+id/prize_table"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="10dp"
android:shrinkColumns="*"
android:stretchColumns="*" />
</HorizontalScrollView>
</ScrollView>
Voilà comment j'ajouter la ligne du tableau:
// header
row = new TableRow(MainActivity.this);
row.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv = new TextView(MainActivity.this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv.setTextSize(18);
tv.setPadding(0, 5, 0, 5);
tv.setText(R.string.prize_no);
row.addView(tv);
tv = new TextView(MainActivity.this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv.setTextSize(18);
tv.setPadding(0, 5, 0, 5);
tv.setText(R.string.prize_name);
row.addView(tv);
layout.addView(row);
for (Prize prize : prizes) {
row = new TableRow(MainActivity.this);
row.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv = new TextView(MainActivity.this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv.setTextSize(18);
tv.setPadding(0, 5, 0, 5);
tv.setText(prize.getPrizeID());
row.addView(tv);
tv = new TextView(MainActivity.this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv.setTextSize(18);
tv.setPadding(0, 5, 0, 5);
tv.setText(prize.getPrizeName());
row.addView(tv);
layout.addView(row);
}
Mais j'ai un problème avec ces codes
- La barre de défilement verticale ne peut correspondre à mon contenu, disons que j'ai 10 lignes, mais la barre de défilement sera 10 fois plus longue
- La barre de défilement horizontale est manquante
Quelqu'un pourrait-il indiquer quel problème dans mon code? Merci à l'avance