2013-11-19 3 views
0

Как кнопки можно выровнять в андроиде, чтобы они имели правильное расстояние сверху, снизу и между кнопками?Как выровнять кнопки?

Текущий код:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"> 
<include 
    android:id="@+id/ActionBackupBar" 
    layout="@layout/actionbar_layout" 
    /> 

<Button 
     android:id="@+id/btnSelectLocation" 
     style="@style/ButtonText" 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5sp" 
     android:layout_marginRight="2sp" 
     android:layout_marginTop="0sp" 
     android:text="@string/activitySelectMyLocationButton" /> 

<Button 
    android:id="@+id/btnCurrentLocation" 
    style="@style/ButtonText" 
    android:text="@string/activitySelectSearchLocationButton" 
    android:layout_marginBottom="5sp" 
    android:layout_marginLeft="5sp" 
    android:layout_marginRight="2sp" 
    /> 

enter image description here

+0

1. Fill_parent устарела, используйте match_parent. 2. Использование sp для полей не имеет смысла. Вместо этого используйте dp. 3. Чего вы хотите достичь? Как вы хотите выровнять эти кнопки? Как на картинке? – Mark

ответ

0

Использование RelativeLayout вместо Linear Layout. Затем вы можете легко выровнять кнопки.

Надеюсь, это может вам помочь.

1

Изменить для RelativeLayout и после того, как попробовать это:

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

<Button 
    android:id="@+id/btnSelectLocation" 
    style="@style/ButtonText" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_centerHorizontal="true" 
    android:layout_centerInParent="true" 
    android:layout_centerVertical="true" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:text="text1" /> 
<Button 
    android:id="@+id/btnCurrentLocation" 
    style="@style/ButtonText" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/btnSelectLocation" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:text="test2" /> 
</RelativeLayout> 
Смежные вопросы