在SpannableStringBuilder中添加图像后更改行

时间:2018-04-12 11:58:06

标签: android android-studio android-edittext spannablestring

我正在添加' xyz' SpannableStringBuilder中的文字我可以在图像添加时改变线条,所以图像在下一行中出现但是在添加图像之后,我希望光标位置在下一行,所以如果我在添加图像后写任何文本它应该来自下一行线。

int selectionCursor = mEdtComment.getSelectionStart();
    mEdtComment.getText().insert(selectionCursor, "\n" + ".");
    selectionCursor = mEdtComment.getSelectionStart();
    SpannableStringBuilder builder = new SpannableStringBuilder(mEdtComment.getText());
    builder.setSpan(new ImageSpan(mRotateBitmap), selectionCursor - ".".length(), selectionCursor,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    mEdtComment.setText(builder);
    mEdtComment.setSelection(selectionCursor);

1 个答案:

答案 0 :(得分:0)

 mEdtComment.setSelection(selectionCursor);

用以下行替换上面的行:

mEdtComment.setSelection(mEdtComment.getText().length());