Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何避免EditText中按钮上的文本重叠?_Android_Android Edittext_Android Button - Fatal编程技术网

Android 如何避免EditText中按钮上的文本重叠?

Android 如何避免EditText中按钮上的文本重叠?,android,android-edittext,android-button,Android,Android Edittext,Android Button,因此,在我的密码字段中,我尝试添加这些图标作为按钮。现在我面临的问题是文本在按钮上重叠。实际上我想要的是按钮留在编辑文本中,但是文本不会重叠,但是你仍然可以写更多的内容,它只是可以滚动的 为此,我使用了带有editText和2个按钮的约束布局。 下面是代码,供参考 <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/customEditTextLayout" android:layout

因此,在我的密码字段中,我尝试添加这些图标作为按钮。现在我面临的问题是文本在按钮上重叠。实际上我想要的是按钮留在编辑文本中,但是文本不会重叠,但是你仍然可以写更多的内容,它只是可以滚动的

为此,我使用了带有editText和2个按钮的约束布局。 下面是代码,供参考

<androidx.constraintlayout.widget.ConstraintLayout
     android:id="@+id/customEditTextLayout"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">

                    <EditText
                        android:id="@+id/editTextPassword"
                        style="@style/editTextInput"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="textPassword"
                        android:letterSpacing="@dimen/letterSpace0_1"

                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent"
                     />

                    <Button
                        android:background="@android:color/transparent"
                        android:id="@+id/eyeIcon"
                        android:layout_width="@dimen/dp30"
                        android:layout_height="wrap_content"
                        android:drawableEnd="@drawable/show_eye_black_24dp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="@+id/editTextPassword"
                        app:layout_constraintEnd_toStartOf="@+id/fingerprintIcon"
                        app:layout_constraintTop_toTopOf="parent"
                        android:layout_marginEnd="@dimen/dp_5"
                        android:elevation="@dimen/dp10"
                        android:padding="@dimen/dp_5"/>

                    <Button
                        android:background="@android:color/transparent"
                        android:id="@+id/fingerprintIcon"
                        android:layout_width="@dimen/dp30"
                        android:layout_height="wrap_content"
                        android:drawableEnd="@drawable/ic_fingerprint_black_24dp"
                        app:layout_constraintEnd_toEndOf="parent"
                        android:layout_marginEnd="@dimen/dp_5"
                        app:layout_constraintHorizontal_bias="0.5"
                        app:layout_constraintTop_toTopOf="parent"
                        android:layout_marginStart="@dimen/dp10"
                        android:padding="@dimen/dp_5"
                        android:elevation="@dimen/dp10"
                        app:layout_constraintBottom_toBottomOf="parent"/>


 </androidx.constraintlayout.widget.ConstraintLayout>

所有视图都有
app:layout\u constraintotop\u toTopOf=“parent”
app:layout\u constraintBottom\u toBottomOf=“parent”
这意味着它们都垂直居中,因此重叠。现在,您希望它们水平放置在同一行上,还是垂直放置在同一行上

编辑:
由于在工作,我无法展示这幅画。您可以通过以下方式实现这一点。现在,您应该阅读并理解提供的链接,该链接通过视觉动画详细解释了它。一开始可能看起来很难,但值得理解,没有它你将无法生活。它将允许您告诉编辑文本永不重叠。

为什么不使用两个垂直方向的线性布局主布局和水平方向的线性布局编辑文本和按钮?不确定这是不是你想要的

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">

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

    <EditText
        android:id="@+id/edit_text_password"
        android:hint="Password"
        android:layout_width="wrap_content"
        android:inputType="textPassword"
        android:layout_weight="10"
        android:layout_height="wrap_content"
        android:gravity="left" />
    <Button
        android:id="@+id/button_show_password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="icon"/>
    <Button
        android:id="@+id/button_fingerprint"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="icon"/>
</LinearLayout>
</LinearLayout>

要防止文本与
按钮重叠,您可以在
编辑文本的末尾设置填充:

android:paddingEnd="90dp"
这样,
EditText
下划线仍将显示在两个
按钮的下方


您好,布局足够好,我的问题是当您在密码字段中写入文本时,它与这些按钮重叠并向前移动。您的密码视图的宽度为
match\u parent
,同时
app:layout\u constraintEnd\u toEndOf=“parent”
app:layou\u constraintStart\u toStartOf=“parent”
。这正常吗?在横向上也是一样的。现在,您可以使用constraintLayout和事件开始和结束来确保它不会重叠。好的,我明白您的意思了,我对editText约束做了一点修改,如果看起来好或不好,可能是idk。你可以在app:layout\u constraintBottom\u toBottomOf=“parent”app:layout\u constraintEnd\u toStartOf=“@id/eyecon”app:layout\u constraintTop\u tototopof=“parent”
上给我一些建议,谢谢你提供了一个快速便捷的解决方案。它也适用于所有尺寸的屏幕,如平板电脑、手机