0

我似乎无法弄清楚如何使用 Android 相对布局做一些简单的事情。html等价物将是这样的......

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

...在我的布局 xml 文件中尝试过这个...

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

...但它看起来就像一堆垃圾。

4

2 回答 2

2

如果您正在寻找一种表格结构,android 提供了 TableLayout,在您的情况下,与 RelativeLayout 相比,它会更有用。下面的链接解释了 TableLayout:

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

于 2013-08-11T23:52:29.173 回答
0

谢谢 Sushil 也许 TableLayout 更适合我的目的,但是我能够像这样锻炼我想要的 RelativeLayout

<?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>
于 2013-08-12T03:20:24.323 回答