Android 在具有特定设计的EditText中放置标签

Android 在具有特定设计的EditText中放置标签,android,android-edittext,textview,Android,Android Edittext,Textview,我需要为Android重写一个iOS应用程序。布局应该相似,我很难解决这个问题: 我想在EditText的左侧有一个标签。它应该粘在那里,不要让EditText文本覆盖标签: 我曾尝试在Android Studio中使用interface builder,如下所示: 问题是,EditText的文本不会隐藏在标签后面。 有什么想法吗 编辑: 由于我的问题不清楚: 我想在EditText中添加一个标签。 它应该贴在左边,并在输入EditText时留有空白。尝试在xml中使用下面的代码并选中,这将

我需要为Android重写一个iOS应用程序。布局应该相似,我很难解决这个问题:

我想在EditText的左侧有一个标签。它应该粘在那里,不要让EditText文本覆盖标签:

我曾尝试在Android Studio中使用interface builder,如下所示:

问题是,EditText的文本不会隐藏在标签后面。 有什么想法吗

编辑: 由于我的问题不清楚:

我想在EditText中添加一个标签。
它应该贴在左边,并在输入EditText时留有空白。

尝试在xml中使用下面的代码并选中,这将使标签文本与用户可以输入密码的密码字段对齐

<androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background"
            android:layout_margin="@dimen/padding_medium">

        <TextView
                android:id="@+id/label"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:text="Password"
                android:layout_marginTop="@dimen/padding_medium"
                android:gravity="center_vertical"
                android:paddingLeft="@dimen/padding_xsmall"
                android:textSize="22sp"
                android:textColor="@android:color/holo_red_dark"
                app:layout_constraintHeight_default="wrap"
                android:paddingStart="@dimen/padding_xsmall"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintWidth_default="wrap"/>

            <com.google.android.material.textfield.TextInputEditText
                    android:layout_width="0dp"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintLeft_toRightOf="@id/label"
                    app:layout_constraintRight_toRightOf="parent"
                    android:layout_marginStart="4dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:background="@null"
                    android:padding="4dp"
                    android:imeOptions="actionNext"
                    android:lines="1"
                    android:inputType="textPassword"/>
    </androidx.constraintlayout.widget.ConstraintLayout>


注意:我在使用新材质设计库时使用了androidx控件。如果您使用的是支持库,则需要将其替换为支持库中的控件。

您能重新表述您的问题吗?它不清楚,无法理解。@KaranMer现在更清楚了吗?若并没有,那个么哪个部分还不清楚?你们想要的标签只会贴在你们的密码字段旁边。对吗?一个与编辑文本重叠的文本视图可能会起作用,不是吗?@KaranMer对-正如vincrichaud所说,它应该重叠。但是当我尝试(见图2)时,它是不正确的。是的,我必须切换到支持库,但它像一个符咒一样工作-谢谢