0

I thought I understood XML.

<?xml version="1.0" encoding="utf-8"?>

<Button
    android:id="@+id/button1"
    android:layout_width="109dp"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:clickable="true"
    android:onClick="closelog"
    android:text="@string/close"
     />



 <Button
    android:id="@+id/sendLogButton"
    android:layout_width="109dp"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:clickable="true"
    android:onClick="sendLog"
    android:text="@string/sendLog" />

<ListView
    android:id="@+id/loglist"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</ListView>

My buttons are not in the correct place on my layouts. Can someone explain to me why my two buttons can't occupy the same horizontal row when they are both the children of the same relative layout. enter image description here

Ryan Gray
  • 824
  • 8
  • 17

2 Answers2

3

You need to wrap the buttons in a relative layout and then use attributes like android:layout_toRightOf="@id/anid and android:layout_toLeftOf="@id/anid to align the buttons to your liking. You also need to delete the layout_gravity.

See this post for more details on align elements in XML.

Community
  • 1
  • 1
Nick
  • 9,285
  • 33
  • 104
  • 147
0

Because of

android:layout_gravity="left"

and

android:layout_gravity="right"

You must wrap 2 button in linear layout or relative layout

Nam Vu
  • 5,669
  • 7
  • 58
  • 90