1

ログイン画面を作りたい。上部に見出しを置き、空白を残してから、ユーザー名とパスワードをそれぞれ 1 行に配置したいと考えています。次に、下部に空白をもう少し残したいと思います。

現在、ユーザー名に対応する LinearLayout にエラーがあり、レンダリングされていないため、TextView と EditTect のパスワードを 1 行にまとめようとはしていません。私が理解するのを手伝ってもらえますか?私のXMLファイルは以下です-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="0px"
        android:layout_weight="2"
        android:gravity="center_horizontal"
        android:text="@string/welcome_message"
        android:textSize="20sp" />



    <View
        android:layout_width="fill_parent"
        android:layout_height="0sp"
        android:layout_weight="4" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0sp"
        android:layout_weight="4"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="User Name" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />
    </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="0sp"
        android:layout_weight="1"
        android:text="Password" />

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="0sp"
        android:layout_weight="1"
        android:inputType="textPassword" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="0sp"
        android:layout_weight="4" />

</LinearLayout>
4

2 に答える 2

1

レイアウト マージンとパディング設定を使用して、ビュー用のスペースを確保します。相対レイアウトの使用をお勧めします

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="0px"
        android:layout_weight="2"
        android:layout_marginTop="30dip"
        android:gravity="center_horizontal"
        android:text="welcome_message"
        android:textSize="20sp" />



    <View
        android:layout_width="fill_parent"
        android:layout_height="0sp"
        android:layout_weight="4" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:padding="10dip"
        android:weightSum="2"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="User Name" />

        <EditText
            android:layout_width="wrap_content" android:layout_weight="1"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:padding="10dip"
        android:weightSum="2"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Password" />

        <EditText
            android:layout_width="wrap_content" android:layout_weight="1"
            android:layout_height="wrap_content" />
    </LinearLayout>

</LinearLayout>
于 2013-05-17T16:35:02.503 に答える