编程方式滚动一个EditText [英] Programatically scrolling an EditText

查看:104
本文介绍了编程方式滚动一个EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个简单的凯撒加密活性。二EditTexts在屏幕上,一个明显的文本,一是加密的。下面是对加密的EditText上一个例子 - 明文一种是类似于

I'm writing a simple caesar-encryption-activity. Two EditTexts on screen, one clear-text, one crypted. Here's an example for the crypted EditText - the cleartext one is similar.

<EditText 
    android:layout_below="@id/Caesar_Label_CryptText"
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent"
    android:id="@+id/Caesar_Text_CryptText" 
    android:hint="Enter crypted text"
    android:maxLines="2" 
    android:lines="2" 
    android:minLines="2"
    android:inputType="text|textMultiLine|textVisiblePassword"
    android:scrollbars="vertical" 
    android:gravity="top" />

现在进入明文时,我有一个TextChangedListener运行的编程隐窝和填补了这个加密的EditText。到目前为止,一切都很好。

Now when entering cleartext I have an TextChangedListener running that programatically crypts and fills that crypto-EditText. So far, so good.

在进入明文变得非常长,明文-滚动的EditText我的开关输入,但加密的EditText停留在文本的顶部。我真的很喜欢这个加密的EditText滚动,使其始终显示其内容的底线。

When the cleartext entered gets really long, the cleartext-EditText scrolls with my imput, but the crypto-EditText stays at the top of the text. I'd really like the crypto-EditText to scroll so that it always shows the bottom line of its content.

那怎么可以做,preferably从onTextChanged() - 在TextWatcher方法

How can that be done, preferably from the onTextChanged()-Method of the TextWatcher?

推荐答案

好了,找到了。这是光标(称作选择上的EditText和TextViews)。

Ok, found it. It was the cursor (called Selection on EditText and TextViews).

这是我怎么得到它的工作:

This is how I got it to work:

ivClear    // assigned the EditText that has the input
ivCrypt    // assigned the target EditText, that I want to scroll
aText      // the input from ivClear, crypted

然后使用:

    ivCrypt.setText(aText);                               // assign the Text
    ivCrypt.setSelection(ivClear.getSelectionStart());    // scroll

呼,终于:)总是低估了Spannable的权力;)

Phew, finally :) Always underestimated the power of the Spannable ;)

这篇关于编程方式滚动一个EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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