Red Cricket
Red Cricket

Reputation: 10470

Trouble understanding Relative Layout

I do not seem to be able to figure out how to do something simple with Android Relative Layout. The html equivalent would be something like this ...

<table>
<tr><td colspan=3><input type="text"></td></tr>
<tr><td><input type="text" size=2></td><td><input type="text" size=2></td><td><input type="text" size=2></td></tr>
</table>

... have tried this in my layout xml file ...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".CreateBookmarksActivity" >

<EditText
    android:id="@+id/editTextBookmarkTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="36dp"
    android:ems="10" >
</EditText>

<EditText
    android:id="@+id/editTextHH"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/editTextBookmarkTitle"
    android:layout_toLeftOf="@+id/editTextMM"
    android:ems="10"
    android:inputType="number" >
</EditText>

<EditText
    android:id="@+id/editTextMM"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/editTextBookmarkTitle"
    android:layout_toRightOf="@+id/editTextHH"
    android:inputType="number" />

</RelativeLayout>

... but it just looks like a jumble of garbage.

Upvotes: 0

Views: 111

Answers (2)

Red Cricket
Red Cricket

Reputation: 10470

Thanks Sushil maybe TableLayout would be more appropriate for my purposes, but I was able to get workout how I want my RelativeLayout like so

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<EditText
    android:id="@+id/bookmark_name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="name" />
<Spinner
    android:id="@+id/bookmark_hh"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_below="@id/bookmark_name"
    android:layout_alignParentLeft="true"
    android:layout_toLeftOf="@+id/bookmark_mm" />
<Spinner
    android:id="@id/bookmark_mm"
    android:layout_width="96dp"
    android:layout_height="wrap_content" 
    android:layout_below="@id/bookmark_name"
    android:layout_toLeftOf="@+id/bookmark_ss" />
<Spinner
    android:id="@id/bookmark_ss"
    android:layout_width="96dp"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@id/bookmark_name" />

<Button
    android:layout_width="96dp"
    android:layout_height="wrap_content"
    android:layout_below="@id/bookmark_hh"
    android:text="@string/done" />
</RelativeLayout>

Upvotes: 0

Sushil
Sushil

Reputation: 8488

In case you are looking for a table kind of structure, android provides TableLayout which in your case will be more useful compared to RelativeLayout. Below link explains TableLayout:

http://developer.android.com/reference/android/widget/TableLayout.html

Upvotes: 2

Related Questions