2011-06-29 20 views

Respuesta

22

Por favor, tome una disposición relativa en virtud de su diseño principal. Establezca su altura y ancho como relleno primario y establezca su gravedad como fondo y coloque cualquier vista de texto o cualquier botón que desee.

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="bottom"> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Bottom Gravity" /> 

    </RelativeLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Without Gravity" /> 

    </LinearLayout> 

</FrameLayout> 

enter image description here

+0

Respuesta perfecta. Trabajos. Pero debería usar "match_parent" en lugar de "fill_parent" – rjdthegreat

+0

Esto también funciona bien para mí –

2

Conjunto android:layout_gravity="bottom". Espero que esto ayude.

6

Depende del diseño que esté utilizando.

En un RelativeLayout hay

android:layout_alignParentBottom="true" 

En un LinearLayout, lo coloca en la parte inferior y asegúrese de establecer los elementos layout_weight correctamente.

También, comprobar la propiedad

android:layout_gravity 

y el aviso que es diferente a

android:gravity 
+0

confirmo su respuesta, él debe usar un plan relativo para fijar el botón en la parte inferior con 'android: layout_alignParentBottom = "true" ', y solo quiero agregar que si quiere mantener su botón al frente, en su código puede llamar al método:' btn.bringToFront() ' – Houcine

0

Deja

android:layout_alignParentBottom="true" 

en su disposición relativa.

+1

Esta respuesta podría mejorarse prestando atención al formateo. – Thomas

0

si alguno tiene dos botones se puede simplemente hacer esto Orkos para mí

<RelativeLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="bottom"> 

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

      <android.support.v7.widget.AppCompatButton 
       android:id="@+id/btn_yes" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="12dp" 
       android:text="Valider"/> 

      <android.support.v7.widget.AppCompatButton 
       android:id="@+id/btn_no" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="12dp" 
       android:text="Annuler"/> 
    </LinearLayout> 

    </RelativeLayout>` 
Cuestiones relacionadas