Search code examples
androidandroid-layoutpositioningandroid-button

Multiple Buttons/Objects on the same row


I want to have Buttons next to each other on the same line, and I want to have one Button next to an EditText.

I have the Eclipse addon, so I have both the graphical layout, as well as the text. I can't post an image, but I'll describe it: it has two TextViews (irrelevant), followed by an EditText, and then a small unlabeled Button on the next line. The next four lines are buttons labeled Turn N, Turn E, Turn S, and Turn W.

So, next to that EditText is where I want the untitled Button to be, and I want the N, E, S, W Buttons to be setup in a compass-like fashion. However, when I try to drag them on the GUI, it binds them to the row, and whenever I try to change the layout, it affects everything, rather than only the one object I'm right-clicking.

How do I fix this?


Solution

  • Something like this:

      <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="TextView" />
    
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/textView1"
            android:text="TextView" />
    
        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/textView2"
            android:layout_toLeftOf="@+id/button1" >
        </EditText>
    
        <Button
            android:id="@id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/textView2"
            android:text="Button" />
    
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/editText1"
            android:layout_centerHorizontal="true"
            android:text="Button" />
    
        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/button2"
            android:layout_toLeftOf="@id/button2"
            android:text="Button" />
    
        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/button2"
            android:layout_toRightOf="@id/button2"
            android:text="Button" />
    
        <Button
            android:id="@+id/button5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/button4"
            android:layout_toLeftOf="@id/button4"
            android:text="Button" />
    
    </RelativeLayout>