chinalwb / Android-Rich-text-Editor

Android Rich Text Editor With customized spans - 富文本编辑器 - Don't miss this one :)
Apache License 2.0
840 stars 169 forks source link

两张图片连续添加的时候,会默认添加一行空格 #79

Open weishubaoforwork opened 4 years ago

weishubaoforwork commented 4 years ago

我们的需求是一张长图,截成多张,然后一起上传,现在每次多加一张图片就会自动多换一行,如何解决?

chinalwb commented 4 years ago

现在已经在用 ARE 了吗?

chinalwb commented 4 years ago
issue_30
chinalwb commented 4 years ago

你需要考虑两处:

  1. ARE_Style_Image.java

    private void insertSpan(ImageSpan imageSpan) {
        Editable editable = this.mEditText.getEditableText();
        int start = this.mEditText.getSelectionStart();
        int end = this.mEditText.getSelectionEnd();
    
        AlignmentSpan centerSpan = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
        SpannableStringBuilder ssb = new SpannableStringBuilder();
    //      ssb.append(Constants.CHAR_NEW_LINE);
        ssb.append(Constants.ZERO_WIDTH_SPACE_STR);
        ssb.append(Constants.CHAR_NEW_LINE);
    //      ssb.append(Constants.ZERO_WIDTH_SPACE_STR);
        ssb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ssb.setSpan(centerSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    //      AlignmentSpan leftSpan = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_NORMAL);
    //      ssb.setSpan(leftSpan, 3,4, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    
        editable.replace(start, end, ssb);
    }
  2. AreImageSpan.java, override getDrawable 方法, 按你的需求改变 drawable 的 bounds

weishubaoforwork commented 4 years ago

之前接入你的代码,这段时间已经去修改了许多代码,现在有点面目全非的意思了,你说的解决方法只是我对drawable的bounds不是太了解,能给我讲讲么

chinalwb commented 4 years ago

我没深究 不过我感觉由于 line spacing 的原因 有一部分空白必不可少 所以需要去改 bounds. 或许还有其他, 只是我能想到的就是上述两点.