2010-05-06 6 views
11

J'ai une disposition relative. Ce qui a 2 boutons, côte à côte et il est aligné à droite.Comment puis-je ajouter un espacement dans RelativeLayout

Donc, ceci est mon fichier XML de mise en page. Ma question est qu'il n'y a pas d'espacement entre le bouton le plus à droite et la bordure droite du RelativeLayout et entre les 2 boutons. Comment puis-je ajouter cela? Je joue avec android: paddingRight, mais rien n'y fait.

Merci.

<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="0dp" android:paddingRight="10dp"> 

    <Button android:id="@+id/1button" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:paddingLeft="10dp" android:paddingRight="10dp"/> 

    <Button android:id="@+id/1button" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/1button" 
     android:paddingLeft="10dp" android:paddingRight="10dp"/> 

Répondre

21

ids Fix et essayer Android: layout_marginRight = "10dip"

1

Vous avez dupliqué des identifiants pour les boutons, essayez de corriger cela et voyez si cela semble correct.

Sinon, votre mise en page semble bonne. Cependant, si vous corrigez le problème d'ID, il y aura 20 pad padding sur la droite (10 de la mise en page et 10 du bouton).

5
android:layout_margin="10dp" 

ou

android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp" 
0

le marginLeft fonctionnait très bien pour moi. J'ai ajouté un TextView vide en tant qu'espaceur afin que tous les enfants ci-dessous puissent s'aligner avec les boutons ci-dessus. Voici un exemple:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <Button android:id="@+id/btnCancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/button_Cancel" 
      android:onClick="returnToConnectionList" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true"/> 
     <TextView 
      android:id="@+id/view_Spacer" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/Label_AddSpacer" 
      android:layout_marginLeft="25dp" 
      android:layout_toRightOf="@id/btnCancel" 
      android:layout_alignParentTop="true"/> 

     <Button android:id="@+id/btnSave" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/button_Save" 
      android:onClick="saveConnection" 
      android:layout_toRightOf="@id/view_Spacer" 
      android:layout_alignParentTop="true"/>