Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.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 - Fatal编程技术网

在android中,使EditText可以在固定长度的字符后水平滚动

在android中,使EditText可以在固定长度的字符后水平滚动,android,android-edittext,Android,Android Edittext,我在android中编辑文本时遇到问题。我正在设置编辑文本的背景,其宽度为“wrap_content”,如下代码所示。但当用户在其中输入大文本时,背景的大小将超过其实际大小 <EditText android:id="@+id/edtEmail" android:layout_width="wrap_content" android:layout_height="wrap_content"

我在android中编辑文本时遇到问题。我正在设置编辑文本的背景,其宽度为“wrap_content”,如下代码所示。但当用户在其中输入大文本时,背景的大小将超过其实际大小

    <EditText
            android:id="@+id/edtEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:background="@drawable/text_field"
            android:hint="@string/email_address"
            android:inputType="textEmailAddress"
            android:paddingEnd="20dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"

            android:scrollHorizontally="true"
            android:singleLine="true" />

所以我希望它在30个字符后可以水平滚动。这样我就不会超过它的实际背景大小。任何帮助都是值得的。
提前感谢

将此属性设置为Edittext,当字符数超过宽度后,它将滚动

android:singleLine="true"

请尝试设置此属性

android:maxEms="4"
这是我的编辑文本

<EditText
    android:id="@+id/edittext_email_address"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:background="@drawable/bg_gray_edittext"
    android:gravity="center"
    android:hint="@string/hint_email_address"
    android:imeOptions="actionNext"
    android:inputType="textEmailAddress"
    android:padding="5dp"
    android:text="abcdefghijklmnopqrstuvwxyz1234567890qwerty1235"
    android:textColor="@color/white"
    android:maxEms="4"
    android:textColorHint="@color/white70"
    android:textSize="20sp" />


希望这能起作用

我已经在我的代码中使用了它现在将编辑文本的宽度固定到一些dps。你会得到你想要的。但是我不能根据我的应用程序模型来固定编辑文本的宽度,它应该在中间水平。有没有办法定义最大字符数,然后才可以滚动