2010-05-06 12 views
11

Tengo un diseño relativo. que tiene 2 botones, uno al lado del otro y alineado a la derecha.¿Cómo puedo agregar espacios en RelativeLayout

Así que este es mi archivo xml de diseño. Mi pregunta es si no hay espacio entre el botón de la derecha y el borde derecho de RelativeLayout y entre los 2 botones. ¿Cómo puedo agregar eso? Juego con android: paddingRight, pero nada ayuda.

Gracias.

<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"/> 

Respuesta

21

identificadores de fijar y tratar androide: layout_marginRight = "10dip"

1

Tiene identificadores duplicados para los botones, intente repararlos y vea si se ve bien.

De lo contrario, su diseño se ve bien. Sin embargo, si soluciona el problema de identificación, habrá 20 espacios de inmersión a la derecha (10 del diseño y 10 del botón).

5
android:layout_margin="10dp" 

o

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

la marginLeft funcionó muy bien para mí. Agregué un TextView vacío como separador, así que ahora todos los niños de abajo pueden alinearse con los botones de arriba. Aquí hay una muestra:

<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"/> 
Cuestiones relacionadas