IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Centrer une TableLayout.


Sujet :

Android

  1. #1
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2009
    Messages : 169
    Points : 171
    Points
    171
    Par défaut Centrer une TableLayout.
    Bonjour,
    Je suis désolé j'ai encore une autre question
    J'essaye de centrer verticalement une TableLayout dans un LinearLayout verticale mais rien n'y fait, je n'y arrive pas.
    Pourtant j'ai tout essayé, layout_gravity / gravity / ne pas les mettre dans les rowTable mais juste dans le TableLayout etc ...
    Voici le code xml =
    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
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
     
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    	android:orientation="vertical" 
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent"
    >
    	<TableLayout
    		android:orientation="vertical"
    		android:layout_width="fill_parent"
    		android:layout_height="wrap_content"
    		android:layout_gravity="center_vertical"
    		android:stretchColumns="1"
    	>
    		<TableRow
    			android:layout_gravity="center_vertical"
    			android:layout_height="wrap_content"
    		>
    			<TextView
    				android:layout_width="wrap_content"
    				android:layout_height="wrap_content"
    				android:text="Identifiant :"
    			/>
    			<EditText
    				android:id="@+id/pseudo"
    				android:layout_width="fill_parent"
    				android:layout_height="wrap_content"
    				android:autoText="false"
    				android:capitalize="none"
    				android:singleLine="true"
    			/>
    			<CheckBox
    				android:id="@+id/checkPref"
    				android:layout_width="wrap_content"
    				android:layout_height="wrap_content"
    				android:text="s'en rappeler"
    				android:textStyle="italic"
    				android:textSize="8px"
    	     	/>		
    		</TableRow>
     
    		<TableRow
    			android:layout_gravity="center_vertical"
    			android:layout_height="wrap_content"
    		>
    			<TextView
    				android:layout_width="wrap_content"
    				android:layout_height="wrap_content"
    				android:text="Mot de passe :"
    			/>
    			<EditText
    				android:id="@+id/mdp"
    				android:layout_width="fill_parent"
    				android:layout_height="wrap_content"
    				android:autoText="false"
    				android:capitalize="none"
    				android:singleLine="true"
    				android:password="true"
    				android:layout_span="2"
    			/>	
    		</TableRow>
    		<View
    			android:layout_height="20px"
    		/>
    		<TableRow
    			android:layout_gravity="center_vertical"
    			android:layout_height="wrap_content"
    		>
    		<View/>
    			<Button
    				android:id="@+id/envoyer"
    				android:layout_height="wrap_content"
    				android:layout_width="fill_parent"
    				android:text="Se connecter"
    				android:onClick="connexion"
    			/>
    		</TableRow>
    	</TableLayout>
    </LinearLayout>
    D'autre part j'ai mis quelques View vide comme séparateur mais je ne sais pas si c'est une bonne méthode.

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    757
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 757
    Points : 968
    Points
    968
    Par défaut
    Essaye de mettre l'attribut center_horizontaly au LinearLayout

  3. #3
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2009
    Messages : 169
    Points : 171
    Points
    171
    Par défaut
    Merci de ta réponse mais ça ne marche pas, j'ai aussi essaye en faisant un layout_height="wrap_content"

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    322
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 322
    Points : 494
    Points
    494
    Par défaut
    Bonjour,

    D'autre part j'ai mis quelques View vide comme séparateur mais je ne sais pas si c'est une bonne méthode.
    A mon avis ce n'est pas une bonne chose de faire ça. A part peut être cas extreme.

    Si tu veux centrer horizontalement ton TableLayout tu dois mettre"wrap_content" à ton attribut layout_width et pas à layout_height.

  5. #5
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2009
    Messages : 169
    Points : 171
    Points
    171
    Par défaut
    Citation:
    D'autre part j'ai mis quelques View vide comme séparateur mais je ne sais pas si c'est une bonne méthode.
    A mon avis ce n'est pas une bonne chose de faire ça. A part peut être cas extreme.
    Que proposes-tu pour éviter cela ?
    Sinon je viens de voir que je me suis trompé dans le sujet, je veux bien sur le centrer verticalement
    J'edit ça de suite pour que les prochaines personnes ne soient pas induit en erreur.

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    322
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 322
    Points : 494
    Points
    494
    Par défaut
    Ahh ok.
    Alors mets orientation="horizontal" dans ton LinearLayout,
    et layout_height="wrap_content" dans ton TableLayout.

    Pour faire un séparateur, utilises plutot les margin ou padding

  7. #7
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2009
    Messages : 169
    Points : 171
    Points
    171
    Par défaut
    Je viens de tester et ca ne marche pas :
    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
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    	android:orientation="horizontal"
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent"
    >
    	<TableLayout
    		android:orientation="vertical"
    		android:layout_width="fill_parent"
    		android:layout_height="wrap_content"
    		android:stretchColumns="1"
    		android:layout_gravity="center_vertical"
    	>
    		<TableRow
    			android:layout_height="wrap_content"
    		>
    			<TextView
    				android:layout_width="wrap_content"
    				android:layout_height="wrap_content"
    				android:text="Identifiant :"
    			/>
    			<EditText
    				android:id="@+id/pseudo"
    				android:layout_width="fill_parent"
    				android:layout_height="wrap_content"
    				android:autoText="false"
    				android:capitalize="none"
    				android:singleLine="true"
    			/>
    			<CheckBox
    				android:id="@+id/checkPref"
    				android:layout_width="wrap_content"
    				android:layout_height="wrap_content"
    				android:text="s'en rappeler"
    				android:textStyle="italic"
    				android:textSize="8px"
    	     	/>		
    		</TableRow>
     
    		<TableRow
    			android:layout_height="wrap_content"
    		>
    			<TextView
    				android:layout_width="wrap_content"
    				android:layout_height="wrap_content"
    				android:text="Mot de passe :"
    			/>
    			<EditText
    				android:id="@+id/mdp"
    				android:layout_width="fill_parent"
    				android:layout_height="wrap_content"
    				android:autoText="false"
    				android:capitalize="none"
    				android:singleLine="true"
    				android:password="true"
    				android:layout_span="2"
    			/>	
    		</TableRow>
    		<View
    			android:layout_height="20px"
    		/>
    		<TableRow
    			android:layout_height="wrap_content"
    		>
    		<View/>
    			<Button
    				android:id="@+id/envoyer"
    				android:layout_width="fill_parent"
    				android:layout_height="wrap_content"
    				android:text="Se connecter"
    				android:onClick="connexion"
    			/>
    		</TableRow>
    	</TableLayout>
    </LinearLayout>
    Ps : je n'ai pas encore enlever les Views, la solution que tu me donnes je l'ai comprise, je pense pouvoir l’implémenter tout seul

    J'ai aussi essayé de mettre la gravite sur le linearLayout vu que ça me paraissais plus logique mais non plus

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    322
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 322
    Points : 494
    Points
    494
    Par défaut
    C'est ça qui ne va pas Tu dois mettre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <View layout_height="20px"/>
    ou une autre valeur


    EDIT : le mieux serait d'utiliser match_parent ou fill_parent suivant la version

  9. #9
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2009
    Messages : 169
    Points : 171
    Points
    171
    Par défaut
    Victoire merci !
    Je posterai le code fini sans les view pour ceux qui auraient eu le même problème.
    Sinon je ne comprend pas trop la logique ici pour le Linearlayout, si je mets l'orientation en verticale ça ne marche pas.
    Ça devrait rien changer normalement vu qu'il ne contient que un élément.


    Edit : code finale
    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
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    	android:orientation="horizontal"
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent"
    >
    	<TableLayout
    		android:orientation="vertical"
    		android:layout_width="fill_parent"
    		android:layout_height="wrap_content"
    		android:stretchColumns="1"
    		android:layout_gravity="center_vertical"
    	>
    		<TableRow
    			android:layout_height="wrap_content"
    		>
    			<TextView
    				android:layout_width="wrap_content"
    				android:layout_height="wrap_content"
    				android:text="Identifiant :"
    			/>
    			<EditText
    				android:id="@+id/pseudo"
    				android:layout_width="fill_parent"
    				android:layout_height="wrap_content"
    				android:autoText="false"
    				android:capitalize="none"
    				android:singleLine="true"
    			/>
    			<CheckBox
    				android:id="@+id/checkPref"
    				android:layout_width="wrap_content"
    				android:layout_height="wrap_content"
    				android:text="s'en rappeler"
    				android:textStyle="italic"
    				android:textSize="8px"
    	     	/>		
    		</TableRow>
     
    		<TableRow
    			android:layout_height="wrap_content"
    			android:paddingBottom="20px"
    		>
    			<TextView
    				android:layout_width="wrap_content"
    				android:layout_height="wrap_content"
    				android:text="Mot de passe :"
    			/>
    			<EditText
    				android:id="@+id/mdp"
    				android:layout_width="fill_parent"
    				android:layout_height="wrap_content"
    				android:autoText="false"
    				android:capitalize="none"
    				android:singleLine="true"
    				android:password="true"
    				android:layout_span="2"
    			/>	
    		</TableRow>
    		<TableRow
    			android:layout_height="wrap_content"
    		>
    			<Button
    				android:id="@+id/envoyer"
    				android:layout_width="fill_parent"
    				android:layout_height="wrap_content"
    				android:text="Se connecter"
    				android:onClick="connexion"
    				android:layout_column="1"
    			/>
    		</TableRow>
    	</TableLayout>
    </LinearLayout>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Centrer une page avec des frames
    Par Nicos77 dans le forum Langage
    Réponses: 11
    Dernier message: 09/11/2005, 16h52
  2. Centrer une page en CSS
    Par maniaco_jazz dans le forum Mise en page CSS
    Réponses: 1
    Dernier message: 11/10/2005, 16h21
  3. [JDialog] Centrer une boite de dialogue.
    Par GETah dans le forum Agents de placement/Fenêtres
    Réponses: 3
    Dernier message: 07/01/2005, 16h44
  4. Centrer une <div> en position fixe sous IE
    Par Jorus dans le forum Mise en page CSS
    Réponses: 8
    Dernier message: 23/09/2004, 15h29
  5. Centrer une feuille sur l'ecran ...
    Par Djedjeridoo dans le forum Composants VCL
    Réponses: 3
    Dernier message: 18/06/2003, 14h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo