2016-11-30 6 views
-2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="center"> 

<Button 
    android:id="@+id/up" 
    android:text="@string/up1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/down"/> 


<Button 
    android:id="@+id/down" 
    android:text="@string/down1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true"/> 

Вот мой код, и я хочу, чтобы кнопка вниз была на самом дне. Как вы можете видеть, у меня есть выравнивание родительского дна. Когда я пытаюсь выровнять свою кнопку вверх, то он центрирует обе кнопки на экране, которые я не хочу. Как я могу это сделать. Помните, что я хочу обе кнопки друг на друга в нижней части экрана. Извините за вопрос о нубе.Выровнять 2 кнопки внизу экрана по вертикали

+0

ОК, так что я понял, что я был глуп. Первый раз с XML, и это полностью пролетело над моей головой. – EnderGeneral149

ответ

1

Удалить android:gravity="center" из вашего относительного расположения и попробовать.

0

Удалить эту строку из RelativeLayout, и он должен работать

android:gravity="center" 
0

Простой один пасты ниже код

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:orientation="vertical"> 

    <Button 
     android:id="@+id/up" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/up1" /> 


    <Button 
     android:id="@+id/down" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/down1" /> 
</LinearLayout> 
</RelativeLayout> 

силы тяжести не работают хорошо для относительного расположения, как указывает название.

0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentBottom="true" 
> 
<Button 
    android:id="@+id/up" 
    android:text="@string/up1" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:weight="1" 
    /> 


<Button 
    android:id="@+id/down" 
    android:text="@string/down1" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:weight="1" 
    /> 
    </LinearLayout> 
    </RelativeLayout> 
0

Попробуйте это:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_gravity="bottom"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="bottom" 
    android:orientation="vertical"> 


    <Button 
     android:id="@+id/up" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/up1" /> 

    <Button 
     android:id="@+id/down" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/down1" /> 

</LinearLayout> 

+0

Yor должен взять LinearLayout и дать андроид: gravity = "bottom" –