Reputation: 61606
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:
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).
Upvotes: 0
Views: 132
Reputation: 2562
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>
Upvotes: 3
Reputation: 22066
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
Upvotes: 2
Reputation: 3966
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>
Upvotes: 4
Reputation: 599
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.
Upvotes: 2