Bonjour,
Comment afficher une table de lignes et colonnes (graphiquement) à partir d'un tableau de valeurs sous Android?
Version imprimable
Bonjour,
Comment afficher une table de lignes et colonnes (graphiquement) à partir d'un tableau de valeurs sous Android?
Apparement c'est un TableLayout.
A quoi sert ces paramètres:
?Code:
1
2
3
4 android:collapseColumns android:shrinkColumns android:stretchColumns
je recherche comment faire un quadrillage pour mon tableau?
Bonjour,
Est ce que ton tableau est un tableau figé ou dynamique ?
C'est-à-dire est ce que le nombre de ligne ou colonne resteront les mêmes ou peuvent elles évoluer ?
elles peuvent évoluer.
Mais je voudrais d'abord afficher un tableau avec un nombre de colonne et lignes connu
le TableLayout peut être utile si ton tableau est fixe.
Si celui ci devient dynamique il va falloir en plus que tu gères l'espace de l'écran , car le fait d'ajouter de nouvelle ligne ou colonne pourra te poser des problèmes.
Tu peux également te créer une vue personnalisé ou tu pourras dans le onDraw de celle ci,te créer directement ton tableau. Tu auras comme cela la largeur et la hauteur de la vue , et ainsi tu pourras définir la hauteur et la largeur de tes cases.
Savez vous comment réaliser le quadrillage du tableau?
Citation:
Savez vous comment réaliser le quadrillage du tableau?
Tu veux savoir dans la vue personnalisé ou dans un TableLayout ?
Dans un TableLayout déclaré dans le code java.
Un exemple :
NB : les couleurs sont flashy :mouarf:Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:stretchColumns="*" android:background="#ff0000"> <TableRow android:background="#00ff00" android:layout_margin="2dip"> <TextView android:text="label1" android:background="#0000ff" android:layout_margin="2dip"/> <TextView android:text="label2" android:background="#0000ff" android:layout_margin="2dip"/> <TextView android:text="label3" android:background="#0000ff" android:layout_margin="2dip"/> </TableRow> <TableRow android:background="#00ff00" android:layout_margin="2dip"> <TextView android:text="label4" android:background="#0000ff" android:layout_margin="2dip"/> <TextView android:text="label5" android:background="#0000ff" android:layout_margin="2dip"/> <TextView android:text="label6" android:background="#0000ff" android:layout_margin="2dip"/> </TableRow> </TableLayout>
oui mais dans le code java ?
Dans le code java
si tu veux ajouter des lignes à ton tableau tu peux faire comme ca
Code:
1
2
3
4
5
6
7
8
9
10
11
12 TableLayout table = (TableLayout) findViewById(R.id.table); TableRow trow=new TableRow(this); TextView tview=new TextView(this); ... trow.addView(tview); .... table.addView(trow);
et pour mettre le quadrillage tu pe utiliser les 2 fonctions suivants
Code:
1
2
3
4 setLayoutParams setsetBackgroundColor
puis je avoir un exemple?
Bonjour,
Si tu sais que ton tableau est fixe, alors pourquoi t'embêter à le faire dans le code :roll: ?Citation:
oui mais dans le code java ?
medi88, t'as déjà donnée un exemple, tu n'as plus qu'a regroupé ce que j'ai posté avec ce que ta proposé medi.Citation:
puis je avoir un exemple?
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 TableLayout tableData = (TableLayout) findViewById(R.id.tabledata); TableRow.LayoutParams tableRowParams =new TableRow.LayoutParams(2); int leftMargin = 10; int topMargin = 10; int rightMargin = 10; int bottomMargin = 20; tableRowParams.setMargins(leftMargin, topMargin, rightMargin,bottomMargin); tablerow = new TableRow(this); tablerow.setLayoutParams(tableRowParams); TextView text = new TextView(this); text.setBackgroundColor(Color.CYAN); tablerow.addView(text); tableData.addView(tablerow,new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT));
Mais cela ne fonctionne pas.
--------------fichier xml ---------
Code:
1
2
3
4
5
6 <TableLayout android:id="@+id/tabledata" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*" android:background="#B9121B"> </TableLayout>
C'est-à-dire ? As tu une erreur ? Quelque chose s'affiche ? ...Citation:
Mais cela ne fonctionne pas.
je n'ai pas les bordures.
Dans mon exemple
Il y a aussi les margin sur les TextView ;).Code:<TextView android:text="label1" android:background="#0000ff" android:layout_margin="2dip"/>
Voilà ce que j'ai fait mais là fond noir, rien ne s'affiche tableau non afficher:
Code:
1
2
3
4 LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); llp.setMargins(2, 2, 2, 2); text.setLayoutParams(llp);
J'avais même pas fais gaffe mais tu affiches quelque chose dans ta TextView au fait ?