より具体的には、この動作の小さな例を示しました。
レイアウト:
<ScrollView
android:id="@+id/scroll_view_for_et"
android:scrollbars="horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<EditText
android:id="@+id/edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top"
android:text="Long text there" />
</ScrollView>
アクティビティ:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editText = (EditText) findViewById(R.id.edit_text);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Adding random span to text
editText.getEditableText().setSpan(new ForegroundColorSpan(Color.RED), 100, 500, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}, 7000);
}
したがって、ある場所にカーソルを設定してから、テキストを別の位置にスクロールすると、7 秒が経過するとカーソルの位置にスクロールして戻ります。この動作を回避するにはどうすればよいですか?
この例の完全なコードのBitBucket リンク。