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

Composants graphiques Android Discussion :

[Layout] Centrer un groupe de View horiontalement


Sujet :

Composants graphiques Android

  1. #1
    Membre émérite
    Avatar de tails
    Homme Profil pro
    Inscrit en
    Novembre 2003
    Messages
    799
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations forums :
    Inscription : Novembre 2003
    Messages : 799
    Billets dans le blog
    15
    Par défaut [Layout] Centrer un groupe de View horiontalement
    Bonjour Je dispose d'un RelativeLayout dans une application, dont les vues devraient être agencées de la manière suivante :
    [image]http://imagik.fr/view-rl/332148[/image]
    Pour ce faire, j'ai définis la layout suivant (peu importe les valeurs strings et colors)
    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
     
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="fill_parent"
      android:background="@color/chronometer_view_layout_background"
      android:orientation="vertical" android:layout_width="fill_parent"
      android:layout_gravity="center_horizontal">
    <TextView 
    android:id="@+id/valeur_chrono"
    android:textStyle="bold"
    android:typeface="monospace"
    android:text="00:00:00"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="50sp"
    android:background="@color/chronometer_background"
    android:textColor="@color/chronometer_foreground"
    android:gravity="center"
    />
    <Button 
    android:id="@+id/action_chrono" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_below="@id/valeur_chrono" 
    android:text="@string/chronometer_action_text_start"
    android:textSize="8sp"/>
    <Button 
    android:id="@+id/initialisation_chrono" 
    android:layout_below="@id/valeur_chrono"
    android:layout_toRightOf="@id/action_chrono"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/initialisation_chrono_text"
    android:textSize="8sp"/>
    <Button 
    android:id="@+id/configuration_chrono" 
    android:layout_below="@id/valeur_chrono"
    android:layout_toRightOf="@id/initialisation_chrono"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/configuration_chrono_text"
    android:textSize="8sp"/>
    </RelativeLayout>
    Ce que je n'arrive pas à faire c'est centrer les 3 boutons de la ligne inférieure. Je saurais le faire en utilisant un LinearLayout pour les grouper, mais j'ai vu que ce n'est pas très recommandé d'imbriquer des Layout. Est-ce possible en RelativeLayout de procéder ainsi sans utiliser de Layout imbriqué ?

    Merci d'avance

  2. #2
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    salut,

    Tu peux le faire comme ça.

    Après pour faire cela juste faire tout en LinearLayout suffit,
    à toi de voir .

    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
     
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="fill_parent"
      android:background="@color/chronometer_view_layout_background"
      android:orientation="vertical" android:layout_width="fill_parent"
      android:layout_gravity="center_horizontal">
    <TextView 
    android:id="@+id/valeur_chrono"
    android:textStyle="bold"
    android:typeface="monospace"
    android:text="00:00:00"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="50sp"
    android:background="@color/chronometer_background"
    android:textColor="@color/chronometer_foreground"
    android:gravity="center"
    />
    <LinearLayout
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_alignParentBottom="true">
    <Button 
    android:id="@+id/action_chrono" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:text="@string/chronometer_action_text_start"
    android:textSize="8sp"
    android:layout_weight="1"/>
    <Button android:id="@+id/initialisation_chrono" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/initialisation_chrono_text"
    android:textSize="8sp"
    android:layout_weight="1"/>
    <Button 
    android:id="@+id/configuration_chrono" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/configuration_chrono_text"
    android:textSize="8sp"
    android:layout_weight="1"/>
    </LinearLayout>
    </RelativeLayout>

  3. #3
    Membre émérite
    Avatar de tails
    Homme Profil pro
    Inscrit en
    Novembre 2003
    Messages
    799
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations forums :
    Inscription : Novembre 2003
    Messages : 799
    Billets dans le blog
    15
    Par défaut
    Salut,

    je te remercie, mais c'est justement ce que je voulais éviter : à savoir, imbriquer deux Layouts. (J'ai mal posé ma question)

  4. #4
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    Tu peux le faire comme ça ,

    Pour ma part je vois ça moins stable .

    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
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="fill_parent"
      android:background="@color/chronometer_view_layout_background"
      android:orientation="vertical" android:layout_width="fill_parent"
      android:layout_gravity="center_horizontal">
    <TextView 
    android:id="@+id/valeur_chrono"
    android:textStyle="bold"
    android:typeface="monospace"
    android:text="00:00:00"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="50sp"
    android:background="@color/chronometer_background"
    android:textColor="@color/chronometer_foreground"
    android:gravity="center"
    />
    <Button 
    android:id="@+id/action_chrono" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:text="@string/chronometer_action_text_start"
    android:textSize="8sp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentBottom="true"
    />
    <Button android:id="@+id/initialisation_chrono" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/initialisation_chrono_text"
    android:textSize="8sp"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    />
    <Button 
    android:id="@+id/configuration_chrono" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/configuration_chrono_text"
    android:textSize="8sp"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    />
    </RelativeLayout>

  5. #5
    Membre émérite
    Avatar de tails
    Homme Profil pro
    Inscrit en
    Novembre 2003
    Messages
    799
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations forums :
    Inscription : Novembre 2003
    Messages : 799
    Billets dans le blog
    15
    Par défaut
    Oui merci . C'est déjà assez proche de ce que je souhaite obtenir
    Je vais encore persévérer pour voir si je peux aboutir au resultat escompté, mais je suis preneur pour d'autres propositions

  6. #6
    Membre émérite
    Avatar de tails
    Homme Profil pro
    Inscrit en
    Novembre 2003
    Messages
    799
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations forums :
    Inscription : Novembre 2003
    Messages : 799
    Billets dans le blog
    15
    Par défaut Avec un TableLayout ?
    Sinon, serait-ce possible avec un TableLayout (ce que j'obtiens, c'est que mes composants du bas se "marchent sur les pieds" et on n'en voit qu'un) ?

  7. #7
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    http://developer.android.com/resourc...blelayout.html

    Dans TableLayout , tu as les options stretchColumns et layout_column pour éviter ce problème.

    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
    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:stretchColumns="1">
    
        <TableRow>
            <TextView
                android:layout_column="1"
                android:text="Open..."
                android:padding="3dip" />
            <TextView
                android:text="Ctrl-O"
                android:gravity="right"
                android:padding="3dip" />
        </TableRow>

  8. #8
    Membre émérite
    Avatar de tails
    Homme Profil pro
    Inscrit en
    Novembre 2003
    Messages
    799
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations forums :
    Inscription : Novembre 2003
    Messages : 799
    Billets dans le blog
    15
    Par défaut Je ne dispose pas de la propriété android:layoutColumn
    Bonjour,

    je re remercie, j'ai progressé dans la disposition graphique. Il faut encore peaufinner

    (Délolé pour les modifications, auxquelles le post suivant fait référence)

  9. #9
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    http://developer.android.com/referen...#layout_column

    API 1
    Mais je ne dispose pas de la propriété layoutColumn dans mon composant Chronometer (car j'ai remplacé le TextView), bien que je l'ai imbriqué dans un TableRow
    layoutColumn appartient à la view TableLayout, il ne te le proposera jamais pour les autres mais il le prendra en compte .

  10. #10
    Membre émérite
    Avatar de tails
    Homme Profil pro
    Inscrit en
    Novembre 2003
    Messages
    799
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations forums :
    Inscription : Novembre 2003
    Messages : 799
    Billets dans le blog
    15
    Par défaut
    Merci

    Effectivement, c'est Eclipse qui ne gère pas très bien l'auto complétion. Mais au final, il n'y a aucune erreur.

    Il faut juste maintenant que je trouve les bonnes valeurs et les bons strectchings

Discussions similaires

  1. Définir layout une fois pour plusieurs views
    Par Timoune007 dans le forum Composants graphiques
    Réponses: 4
    Dernier message: 04/07/2015, 00h16
  2. Layout centrer éléments
    Par jojo_ol76 dans le forum Composants graphiques
    Réponses: 2
    Dernier message: 03/02/2013, 14h23
  3. Centrer un groupe de div en mode float
    Par electroremy dans le forum Mise en page CSS
    Réponses: 1
    Dernier message: 24/11/2009, 00h28
  4. [SQL] Problème group by sur view
    Par helene34 dans le forum Oracle
    Réponses: 2
    Dernier message: 04/01/2007, 08h25
  5. Réponses: 1
    Dernier message: 20/12/2006, 22h14

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