-1

I need to put two buttons side by side, centered and aligned to bottom. At the moment they're both bottomed and centered, but they're over each other and I need them side by side

<Button
    android:id="@+id/uploadButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="UPLOAD" />


<Button
    android:id="@+id/removeButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="REMOVE" />
Mahm00d
  • 3,881
  • 8
  • 44
  • 83
  • 3
    Does this answer your question? [2 buttons side by side - android layouts](https://stackoverflow.com/questions/5551349/2-buttons-side-by-side-android-layouts) – Javad Dehban Jul 27 '20 at 08:21

3 Answers3

1

Try this layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/uploadButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:text="UPLOAD" />


        <Button
            android:id="@+id/removeButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:text="REMOVE" />
        
    </LinearLayout>

</RelativeLayout>
Hai Hack
  • 948
  • 13
  • 24
1

You can use a linear layout and put the buttons in that layout. and add layout_weight to the buttons. Like this:

<LinearLayout 
    android:id="@+id/LinearLayout" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:layout_alignParentBottom="true">

    <Button
    android:id="@+id/uploadButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="UPLOAD"
android:layout_weight="1" />

    <Button
    android:id="@+id/removeButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="REMOVE" 
android:layout_weight="1"/>
</LinearLayout>
Zoe
  • 27,060
  • 21
  • 118
  • 148
Saurav Kumar
  • 61
  • 1
  • 12
0

Give weight to them:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

     <Button
            android:id="@+id/uploadButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
    android:layout_weight="1"
            android:text="UPLOAD" />
        
        
        <Button
            android:id="@+id/removeButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
    android:layout_weight="1"
            android:text="REMOVE" />
<LinearLayout/>
MMG
  • 3,226
  • 5
  • 16
  • 43