0

I am coming back to Android after a really long absence and it turns out, I've pretty much forgotten everything.

I want to a build a UI like this:

enter image description here

The buttons Item1 and Item2 trigger a move to another page, while the Perform Action button does an action in place. And the ad should be docked to the bottom of the screen.

What layout should I pick to achieve this UI? I am targeting Android 2.2 (if that matters).

AngryHacker
  • 59,598
  • 102
  • 325
  • 594

4 Answers4

4

I believe going for a Relative Layout helps. May be this can help, although you might want to reshuffle things a bit.

<?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" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="42dp"
            android:text="@string/item1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/button1"
            android:layout_below="@+id/button1"
            android:layout_marginTop="48dp"
            android:text="@string/item2" />

        <Button
            android:id="@+id/button4"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="@string/ad_goes_here" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/button2"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="62dp"
            android:text="@string/perform_action" />

    </RelativeLayout>
Ghost
  • 3,966
  • 1
  • 25
  • 36
  • +1 for exact catch, but please elaborate you answer with example as the himself mentions he forgets everything – ingsaurabh Dec 21 '11 at 06:35
  • @AngryHacker: I've inserted button at the place of that ad. You can always change it with the exact description that suits your ad. – Ghost Dec 21 '11 at 06:39
3
I think using Linear Layout is best


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

<Button
 android:id="@+id/btn1"
 android:text="Item1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" android:layout_gravity="center"
 />

<Button
 android:id="@+id/btn2"
 android:text="Item2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" android:layout_gravity="center"
 />
<Button
 android:id="@+id/btn3"
 android:text="Perform Action"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" android:layout_gravity="center"
 />

<Button
 android:id="@+id/btn4"
 android:text="Ad Goes here"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" android:layout_gravity="center"
 />

</LinearLayout>
sai
  • 2,562
  • 8
  • 31
  • 46
2

You can use a LinearLayout with android:orientation="vertical". However there are many other layouts which are able to achieve your desired UI. I prefer to just stick to LinearLayout because I could just set it to either vertical or horizontal.

Hend
  • 589
  • 5
  • 15
  • 35
  • how would I ensure that the ad is docked to the bottom? – AngryHacker Dec 21 '11 at 06:31
  • 1
    If you need to dock items at bottom for example, then relative layout, like Rahul said, would help. You could use `android:layout_alignParentBottom`. Take a look at this question - http://stackoverflow.com/questions/2386866/how-to-align-views-at-the-bottom-of-the-screen – Hend Dec 21 '11 at 06:38
2

You can continue with relative layout in this layout you need to use list-view(simple) and drag button at below of listview. and at the bottom place your advertice sdk area will be stay

For more detail....

Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133