Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android layout with 2 evenly spaced Buttons

I have this layout that works correctly, a relative layout with a text view and two buttons spaced evenly below it.

<RelativeLayout android:id="@+id/entrypopup"
            android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:padding="5px"
    android:visibility="gone"
    android:layout_below="@+id/ad"
    android:background="#80000000">
    <TextView android:id="@+id/title" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="Entry Popup..."
        android:textColor="#ffffffff"
        android:textSize="20sp" />
    <TableLayout android:id="@+id/TableLayout01"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:layout_below="@id/title">
        <TableRow android:layout_weight="1">
            <Button android:id="@+id/buttonVisit" android:text="View"
                android:layout_height="fill_parent"
                android:layout_width="0dip"
                android:layout_weight="1"/>
            <Button android:id="@+id/buttonCancel" android:text="Cancel"
                android:layout_width="0dip"
                android:layout_weight="1" 
                android:layout_height="fill_parent"/>
        </TableRow>
    </TableLayout>
</RelativeLayout>

But running layoutopt it says that "this TableRow layout or its TableLayout parent is possible useless".

Is there a way to do this layout then without the tables?

like image 213
Robby Pond Avatar asked Apr 08 '10 23:04

Robby Pond


People also ask

Is it possible to evenly distribute buttons across the width of an android LinearLayout?

I suggest you use LinearLayout's weightSum attribute. Adding the tag android:weightSum="3" to your LinearLayout's xml declaration and then android:layout_weight="1" to your Buttons will result in the 3 buttons being evenly distributed.

How do you give a space between two buttons in android linear layout?

Use android:layout_marginTop="10.0dip" on second button. Show activity on this post.

How do you put a space between buttons in linear layout?

good answer. Small improvement: use a <Space android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="1" > </Space> instead of a <View> to make your objective clearer in your XML.

How do I change the space between two buttons in android?

Notice the line that says android:layout_marginTop="10dip" which ensures that you leave a reasonable 10 dip space in between your buttons. Ofcourse, you can increase (or decrease) that space in between your buttons. That's your choice. Hope this answered your question satisfactorily.


1 Answers

Dump the TableLayout and TableRow, and just use a horizontal LinearLayout in their place. The "magic" is in your 0dip width and 1 weight, which you already have.

like image 67
CommonsWare Avatar answered Oct 21 '22 19:10

CommonsWare