0

だから私はAndroidのレイアウトの初心者で、学んでいRelativeLayoutます。私は次のことをしようとしています:

ここに画像の説明を入力

ただし、仮想デバイスで取得できるのは、スペース (幅と高さ) の 100% を占める名前フィールドだけです。
ここに画像の説明を入力

ここに私のXMLがあります:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/root">
    <EditText android:id="@+id/name" 
        android:layout_alignParentLeft="true" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:hint = "Name"/>
    <EditText android:id="@+id/phone" 
        android:layout_below="@id/name" 
        android:layout_alignParentRight="true" 
        android:layout_weight="0.4" 
        android:layout_height="wrap_content" 
        android:layout_width="0dp" 
        android:hint="Phone" />
    <EditText android:id="@+id/email" 
        android:layout_below="@id/phone" 
        android:layout_alignParentRight="true" 
        android:layout_weight="0.4" 
        android:layout_height="wrap_content" 
        android:layout_width="0dp" 
        android:hint="Email" />
    <EditText android:id="@+id/dob" 
        android:layout_below="@id/email" 
        android:layout_alignParentRight="true" 
        android:layout_weight="0.4" 
        android:layout_height="wrap_content" 
        android:layout_width="0dp" 
        android:hint="D.O.B." />
    <EditText android:id="@+id/address" 
        android:layout_below="@id/phone" 
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/dob"
        android:layout_weight="0.6" 
        android:layout_height="0dp" 
        android:layout_width="match_parent" 
        android:hint="Address" />
    <Button android:id="@+id/submit" 
        android:layout_weight="1.0" 
        android:layout_below="@id/address" 
        android:layout_height="match_parent" 
        android:layout_width="0dp" 
        android:text="Submit"/>
</RelativeLayout>  

何がうまくいかないのですか?

4

3 に答える 3

2

出力の xml は次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<EditText
    android:id="@+id/name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:hint="Name" />

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/phone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true
        android:layout_weight="-10"
        android:hint="Phone" />

    <EditText
        android:id="@+id/email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/phone"
        android:layout_weight="0.4"
        android:hint="Email" />

    <EditText
        android:id="@+id/dob"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/email"
        android:layout_weight="0.4"
        android:hint="D.O.B." />

    <EditText
        android:id="@+id/address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/phone"
        android:layout_toLeftOf="@id/dob"
        android:layout_weight="0.6"
        android:hint="Address" />
</RelativeLayout>

<Button
    android:id="@+id/submit"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"                
    android:text="Submit" />

</LinearLayout>
于 2013-07-04T10:57:21.890 に答える
1

name 要素の layout_height を次のように変更します。 android:layout_height="wrap_content"

于 2013-07-04T10:48:53.397 に答える
1

レイアウト XML を上記のように変更します。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<EditText
    android:id="@+id/name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:hint="Name" />

<LinearLayout
    android:id="@+id/linear"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/name"
    android:orientation="horizontal"
    android:layout_marginBottom="60dp"
    android:weightSum="1" >

    <EditText
        android:id="@+id/address"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.6"
        android:hint="Address" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="0.4"
        android:weightSum="3" >

        <EditText
            android:id="@+id/phone"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:hint="Phone" />

        <EditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:hint="Email" />

        <EditText
            android:id="@+id/dob"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:hint="D.O.B." />
    </LinearLayout>
</LinearLayout>

<Button
    android:id="@+id/submit"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true"
    android:text="Submit" />

</RelativeLayout>

それが役立つことを願っています:)

于 2013-07-04T11:03:27.730 に答える