您的位置:首页 > 移动开发 > Android开发

android EditText多行文本输入的若干问题

2015-05-15 15:22 357 查看
以前习惯了网页以及swing上的文本框输入,现在到Android上突然没有了这种控件,刚开始使用起来还是比较费力的。为了想实现多行文本框的输入及显示效果,逐一解决了如下问题:

1. 如何让EditText显示成为一个文本框的区域用来输入;

2. 光标从首行开始显示;

3. 如何是设置卷轴;

4. 如何固定文本框的大小。

5. 如何让文本框显示边线;

为了达到如下的效果,我们做了如下的工作:



<EditText
    android:id="@+id/add_content"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:enabled="true"
    android:gravity="top"
    android:inputType="textMultiLine"
    android:minLines="8"
    android:maxLines="10"
    android:scrollbars="vertical" 
    android:background="@android:drawable/edit_text"
    >
</EditText>


上面 是这个控件效果的xml

一下两行用来显示输入区域的效果;

android:inputType="textMultiLine"
    android:minLines="8"


android:background="@android:drawable/edit_text"  <!-用来显示<span id="0_nwp" style="width: auto; height: auto; float: none;"><a target=_blank id="0_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?c=news&cf=2&ch=0&di=128&fv=17&jk=bfb3aba9d5e662dc&k=%BF%D8%BC%FE&k0=%BF%D8%BC%FE&kdi0=0&luki=1&n=10&p=baidu&q=72008038_cpr&rb=0&rs=1&seller_id=1&sid=dc62e6d5a9abb3bf&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1893960&u=http%3A%2F%2Fwww%2Echengxuyuans%2Ecom%2FAndroid%2F79282%2Ehtml&urlid=0" target="_blank" mpid="0" style="text-decoration: none; color: rgb(26, 100, 162);"><span style="color: rgb(0, 0, 255); width: auto; height: auto;">控件</span></a></span>的边线->
android:maxLines="10"
    android:scrollbars="vertical"
以上两行用来设置区域的最大行数是10,超过10行之后会以“竖直卷轴”的形式显示。

android:gravity="top"  <!-用来设置光标的起始位置从顶行开始,否则默认情况下是从中间行开始->


转载注明地址:http://www.chengxuyuans.com/Android/79282.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: