编程方式滚动一个EditText方式、EditText

由网友(ζ情愿一生)分享简介:我在写一个简单的凯撒加密活性。二EditTexts在屏幕上,一个明显的文本,一是加密的。下面是对加密的EditText上一个例子 - 明文一种是类似于I'm writing a simple caesar-encryption-activity. Two EditTexts on screen, one clear-...

我在写一个简单的凯撒加密活性。二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 ;)

阅读全文

相关推荐

最新文章