0

数日前、ユーザー名入力用の「ラベル」を内部に持つ edittext 実装を探していました。Stackoverflow から次の xml コードを見つけました。

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_margin="10dp">

        <EditText
            android:id="@+id/username_editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="15sp"
            android:hint="Πατήστε εδώ"
            android:inputType="text"
            android:maxLength="20"
            android:paddingLeft="125dp"
            tools:ignore="HardcodedText" >

             <requestFocus />
        </EditText>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginBottom="0dp"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="0dp"
            android:paddingLeft="12dp"
            android:text="Όνομα χρήστη:"
            android:textColor="@color/grey"
            android:textSize="15sp"
            tools:ignore="HardcodedText" />

        </FrameLayout>

結果は、1 つのことを除いて、私が必要としていたものでした。 ここに画像の説明を入力

整列していないことがわかるように、赤い線を引きます。何か助けはありますか?

4

2 に答える 2

3

テキストを揃えるには、コンポーネントのレイアウト パラメータandroid:layout_alignBaselineを持つ Relativelayout が必要です。これを試して、最新情報を入手してください:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp" >

    <EditText
        android:id="@+id/username_editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:inputType="text"
        android:ems="10"
        android:maxLength="20"
        android:textSize="15sp"
        android:hint="Πατήστε εδώ"
        android:paddingLeft="125dp" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/username_editText"
        android:layout_alignBottom="@+id/username_editText"
        android:layout_alignParentLeft="true"
        android:paddingLeft="10dp"
        android:text="Όνομα χρήστη:"
        android:text="TextView" />

</RelativeLayout>
于 2013-05-19T18:56:15.313 に答える