ログイン画面をデザインしたい。コンテンツは、水平および垂直に中央揃えにする必要があります。これまでのところ、私はこれを作成しました:
現在、一番上の要素、つまりアイコンに marginTop を指定しています。しかし、それは適切な方法ではないと思います。ユーザー名フィールドを画面の垂直中央に配置したい。これにより、コンテンツ全体が画面の中央に移動します。
これまでの私のレイアウトコードは次のとおりです。
<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"
tools:context=".LoginActivity"
android:background="#d1d6df">
<ImageView
android:id="@+id/imgIcon"
android:src="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="Icon"
android:layout_marginBottom="20dp"
android:layout_marginTop="120dp"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/txtUsername"
android:hint="Username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/imgIcon"
android:ems="10"
android:inputType="text">
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtPassword"
android:hint="@string/passwordHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/txtUsername"
android:ems="10"
android:inputType="textPassword">
</EditText>
<Button
android:text="@string/loginButtonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/txtPassword"
/>
</RelativeLayout>
また、ログイン ボタンの幅を上位の兄弟、つまりパスワード フィールドから取得したいと考えています。それは可能ですか?