0

Android Relative Layout で簡単なことをする方法を理解できないようです。同等の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 に答える