views:

42

answers:

1

Hi guys,

I've spent so much time trying to figure this out. I'm building a dialog layout and trying to get the Title centered relative to the dialog while having 2 buttons on either side of the title. The buttons are to be 'gravity-ed' towards far left and far right.

The easy part is centering the dialog, OR doing the buttons far left and far right. It's getting them to play nice with each other on the same line.

Easy way to think about it:

  1. Title is centered in dialog
  2. 2 Buttons are independently aligned left and right on the same line

Any thoughts on how to do this?

Thanks,

Justin

A: 

IMO I would try to do a customized dialog, and use a TableLayout to place your elements. This way you can put your buttons, and use the attribute stretchcolumn on the title to push the buttons on the side of the screen. (If I understood you well)
alt text
if you go with this xml example, it should work and be independant from screen size/rotation:

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

<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <Button android:text="Button01" android:id="@+id/Button01"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <TextView android:text="This is your title" android:id="@+id/TextView01"
        android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" ></TextView>
    <Button android:text="Button02" android:id="@+id/Button02"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</TableRow>
</TableLayout>
Sephy
Thanks Sephy for the quick reply. This would work if I could guarantee the screen size? Like, I wouldn't know how far to push the right/left buttons on an unknown resolution or is there an attribute that I don't fully understand yet that allows this. Thanks.
nitsujri
Don't think you need to know the size of the screen...I'll do some tests for you and edit my post.
Sephy