Bonjour à tous et à toutes,
J'en profite pour vous glisser une petite astuce afin de placer vos boutons en bas de page. Puis j'aurais une question à ce sujet
Voici comment procéder dans le fichier xml de votre vue:
Tout d'abord, nous utilisons un RelativeLayout:
Ensuite, nous plaçons nos boutons comme ceci:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent">
Remarques:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 <LinearLayout android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content"> <Button android:textSize="20sp" android:id="@+id/btnprecedent" android:text="@string/precedent" android:onClick="onClick" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" /> <Button android:textSize="20sp" android:id="@+id/btnsuivant" android:text="@string/suivant" android:onClick="onClick" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout>
_ android:layout_alignParentBottom="true" Permet de placer le Layout contenant les boutons en bas de l'écran.
_ android:text="@string/precedent" Ce texte est défini dans un fichier string.xml
_ android:onClick="onClick" Ceci permet de gérer le clique sur le bouton dans mon Activity via la fonction "public void onClick (View v)" à définir bien sure.
Puis, nous mettons le reste de la vue dans un ScrollView comme ceci:
Remarque: Le ScrollView doit contenir qu'un seul élément! Donc nous plaçons le tout dans un LinearLayout.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> ......... ......... ......... </LinearLayout> </ScrollView>
Et on n'oublie pas de fermer le RelativeLayout:
Voila pour l'astuce
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 </RelativeLayout>
Maintenant la question
Tout fonctionne parfaitement bien. Cependant, lorsque j'affiche le clavier virtuel mes boutons remontent. J'aimerai pouvoir scroller afin que mes boutons restent en bas de la page même avec le clavier virtuel!
Quelqu'un aurait une solution?
Merci d'avance![]()
Partager