EditText不会写到单行 [英] EditText won't write into single line

查看:69
本文介绍了EditText不会写到单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个计算器,用户输入包含在EditText中.输入是通过屏幕上的按钮输入的,因此Android键盘已禁用.但是,我希望它将所有输入都写在一行中,并且当行到达边框时,需要先将其椭圆化,然后再水平滚动才能看到整个文本.

I'm making a calculator and user input is contained in EditText. Input is typed through buttons on screen, so Android keyboard is disabled. However, I want it to write all input in one line and when line reaches border, it needs to be ellipsized and then horizontally scrollable so you can reach whole text.

我尝试通过设置android:maxLines ="1"和android:ellipsize ="end"来做到这一点,但这不起作用.文本仍处于多行中,但仅可见一行,您需要垂直滚动才能看到其他行.我也尝试使用android:singleLine ="true",但这会使EditText完全无法使用.

I tried doing this by setting android:maxLines="1" and android:ellipsize="end", but that doesn't work. Text is still in multiple lines, but only one line is visible and you need to scroll vertically to see other lines. I also tried using android:singleLine="true", but that makes EditText completely unusable.

这是EditText XML:

This is EditText XML:

<EditText
     android:id="@+id/textView"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_gravity="end"
     android:background="@color/colorBlue"
     android:textAlignment="textEnd"
     android:textSize="40sp" />

推荐答案

我认为这对您有用.让我知道它是否有效.

I think this will work for you. Let me know if it works.

<EditText
 android:id="@+id/textView"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:layout_gravity="end"
 android:background="@color/colorBlue"
 android:textAlignment="textEnd"
 android:textSize="40sp"
 android:inputType="text" 
 android:maxLines="1"
 android:lines="1"
 android:scrollHorizontally="true"
 android:ellipsize="end"/>

帖子也可能对您有所帮助.

This post might help you as well.

这篇关于EditText不会写到单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆