SpannableStringBuilder with ImageSpan errors with cursor height

I have an EditText and I add images to it after adding the image, if I wrote with the keyboard everything is fine, but when I press the spacebar once or twice or ... the cursor gets the same image height, so when it goes to a new line the new line is displayed as height, like an image. Can someone help me with this. This is the same problem TextView with ImageSpan messed up line height

 private void addImageBetweentext(Drawable drawable) {


    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());

    int selectionCursor = editText.getSelectionStart();
    editText.getText().insert(selectionCursor, "  .");
    selectionCursor = editText.getSelectionStart();

    SpannableStringBuilder builder = new SpannableStringBuilder(editText.getText());
    builder.setSpan(new ImageSpan(drawable), selectionCursor - "  ".length(), selectionCursor, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    editText.setText(builder);

    editText.setSelection(selectionCursor);

      

PRoblem on Android 6

+3


source to share





All Articles