Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I achieve the following result using RelativeLayout?

Pictures: http://img838.imageshack.us/img838/1402/picse.png

How do I make the layout in Pic. 2 using RelativeLayout ONLY. Below is the xml layout of the first screenshot.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
<TextView
    android:id="@+id/timer_textview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_marginTop="10dip"
    android:textSize="30sp"
    android:layout_alignParentTop="true"
    android:text="@string/timer_start" />

<ListView 
    android:id="@+id/questions_listview"
    android:layout_below="@id/timer_textview"  
    android:layout_width="wrap_content"
    android:layout_height="fill_parent" />

<Button android:id="@+id/true_btn"
    android:text="@string/true_option"
    android:layout_alignParentBottom="true"
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/false_btn"
    android:text="@string/false_option"
    android:layout_toRightOf="@id/true_btn"
    android:layout_alignBaseline="@id/true_btn"
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</RelativeLayout>
like image 671
Ragunath Jawahar Avatar asked Aug 24 '10 11:08

Ragunath Jawahar


1 Answers

You could use LinearLayout at bottom to achieve this. But you want to use RelativeLayout layout only so:

<RelativeLayout android:layout_width="fill_parent" ... >

...    

<View android:id="@+id/helper" 
android:layout_width="0dp"
android:layout_height="0dp" 
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />

<Button android:id="@+id/true_btn"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:layout_toLeftOf="@id/helper"/>

<Button
android:id="@+id/false_btn"
android:layout_alignBaseline="@id/true_btn"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:layout_toRightOf="@id/helper" />

</RelativeLayout>

Can't you really use nested layouts?

like image 118
plugmind Avatar answered Oct 23 '22 02:10

plugmind