-1

ここに私が欲しいものがあります:

ここに画像の説明を入力

iOSではこれはとても簡単ですが、Androidでは不可能のようです。何があっても、テキストボックスを画面の中央に配置したい。画像を追加すると、テキスト ボックスが中央揃えになっていて画像が中央揃えになっていない場合でも、テキスト ボックスがずれます。アイコンを中央揃えにしたいのですが、同じレイアウトでないと難しいようです。それらをすべて同じ相対レイアウトに配置する必要がありますか?

重みを使用してすべてに適切な高さの寸法を与えるためにメイン レイアウトを線形レイアウトとして使用し、個々の相対レイアウトまたは線形レイアウトを重み付けします。これは受け入れられたパターンですか?

アイコン textViews および textEdits の 1 つの例を次に示します。

            <RelativeLayout
                android:id="@+id/passwordRelativeLayout"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="83"
                android:gravity="center">

                <ImageView
                    android:id="@+id/passwordImageView"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:adjustViewBounds="true"
                    android:contentDescription="@string/email_ph"
                    android:gravity="center_horizontal"
                    android:src="@mipmap/lock_icon"
                    android:layout_alignParentBottom="true"
                    android:layout_toStartOf="@+id/passwordTextView" />

                <TextView
                    android:id="@+id/passwordTextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_alignStart="@+id/passwordEditText"
                    android:labelFor="@+id/passwordEditText"
                    android:text="@string/password"
                    android:textColor="@color/white"
                    android:textSize="24sp" />

                <EditText
                    android:id="@+id/passwordEditText"
                    android:layout_width="500dp"
                    android:layout_height="45dp"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentEnd="true"
                    android:layout_below="@+id/passwordTextView"
                    android:layout_gravity="center_horizontal"
                    android:background="@mipmap/text_box_background"
                    android:gravity="center"
                    android:inputType="textPassword" />
            </RelativeLayout>\

これには余白の設定はありませんが、今のところ、ピクセルの完璧なセンタリング設定を取得することに関心があります.

4

2 に答える 2

0

どうぞ: drawableLeft のように、いくつか変更する必要があります。これをメールの mipmap に変更し、mipmap をロックします。変更できるいくつかの異なる ID とレイアウトの背景を除いて、これは機能するはずです。 動作することの証明

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical"
>


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

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2.8"
        android:text="Email"
        android:textAlignment="viewStart"
        android:textColor="@android:color/black"
        android:textSize="20sp"
        android:gravity="bottom"
        />

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2.8" />


</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/edittext2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:drawableStart="@mipmap/ic_launcher"
        android:inputType="text"
        android:selectAllOnFocus="false"
        android:textColor="@android:color/black"
        />

</LinearLayout>

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

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2.8"
        android:text="Password"
        android:textAlignment="viewStart"
        android:textColor="@android:color/black"
        android:textSize="20sp"
        android:gravity="bottom"
        />

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2.8" />


</LinearLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">


    <EditText
        android:id="@+id/edittext1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableStart="@mipmap/ic_launcher"
        android:inputType="text"
        android:textColor="@android:color/black" />


</LinearLayout>

<View
    android:layout_width="match_parent"
    android:layout_height="10dp" />

</LinearLayout>
于 2017-04-08T00:07:24.030 に答える