klinker24/Android-TextView-LinkBuilder

After setting the link, maxlines and ellipsize-> end Settings are invalid.

Closed this issue · 10 comments

After setting the link, maxlines and ellipsize-> end Settings are invalid.

Those options redraw the text, with your spans gone. You will just need to do the LinkBuilder at the end of that process instead of the beginning.

I'm not saying that the link effect is invalid. It says that the ellipsize end does not display the ellipses, and the link effect is disabled to display the ellipsis.

Sorry I don't understand what that means. A screenshot, or even better, a workable sample, would make this easier to look in to.

tim 20180523202116
ellipsize effect is invalid

I don't know if I am going to be able to do anything about that, sorry. Like I said earlier, those settings change the text that is in the TextView. When that text changes, it removes the modifications that I make to it. I can re-open this issue, but I don't think a fix is likely from me. You may be able to do it with a custom TextView that changes when the ellipsis are added, or when the links are created.

I solved the problem, I doubt character length might be the problem, because I still see don't know much about the kotlin language, so I use or previous versions, my first solution is to set up the Link, span, and then set the settext(), HTML code is as follows, the effect is normal, hard the author.
tim 20180523203557

I'm sorry to disturb you again. I found a problem. I haven't found a solution for the time being. Set Link, maxlines, Textview Click to roll.
tim 20180528113812
tim 20180528113942

---Set Link, maxlines, Textview Click to roll.
@yxyaxng do you solve this problem? I have the same problem.
and @klinker24, would you check this bug?

public class CustomMovementMethod extends BaseMovementMethod {

    private static CustomMovementMethod customMovementMethod;

    public static CustomMovementMethod getInstance() {
        if (customMovementMethod == null) {
            synchronized (CustomMovementMethod.class) {
                if (customMovementMethod == null) {
                    customMovementMethod = new CustomMovementMethod();
                }
            }
        }
        return customMovementMethod;
    }

    @Override
    public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
        int action = event.getAction();

        if (action == MotionEvent.ACTION_UP ||
                action == MotionEvent.ACTION_DOWN) {
            int x = (int) event.getX();
            int y = (int) event.getY();

            x -= widget.getTotalPaddingLeft();
            y -= widget.getTotalPaddingTop();

            x += widget.getScrollX();
            y += widget.getScrollY();

            Layout layout = widget.getLayout();
            int line = layout.getLineForVertical(y);
            int off = layout.getOffsetForHorizontal(line, x);

            ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);

            if (link.length != 0) {
                if (action == MotionEvent.ACTION_UP) {
                    //除了点击事件,我们不要其他东西
                    link[0].onClick(widget);
                }
                return true;
            }
        }
        return true;
    }

    private CustomMovementMethod() {

    }
}

@yxyaxng @lazyfatcat @klinker24 Textview will not auto scroll when use CustomMovementMethod

image
@Pluckypan 我这样使用,还是无效的。Textview被setmaxline之后还是会滚动