Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i set spannablestring in the text,it works error in recycleview when i collapse the it #58

Open
i2863CookieZJ opened this issue Feb 11, 2018 · 2 comments

Comments

@i2863CookieZJ
Copy link

i need collaspe the last few lines of the article, but it collaspe the first few lines of the article,can u help me?

@i2863CookieZJ
Copy link
Author

I was positioned to the problem,when i let the textview setMovementMethod,the probrom occurred.can u give me some suggestion

@i2863CookieZJ
Copy link
Author

i solve it.
if someone has the same problem,it maybe can help u.
when u setMovementMethod for textview,u also let it scroll. u need prohibit it,so overridde the LinkMovementMethod like this:

public class NoScrollLinkMovementMethod implements OnTouchListener {
@OverRide
public boolean onTouch(View v, MotionEvent event) {
TextView widget = (TextView) v;
Object text = widget.getText();
if (text instanceof Spanned) {
Spanned buffer = (Spanned) text;

        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);
                } else if (action == MotionEvent.ACTION_DOWN) {
                    // Selection only works on Spannable text. In our case setSelection doesn't work on spanned text
                    //Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
                }
                return true;
            }
        }

    }

    return false;
}

then, setOnTouchListener replace setMovementMethod, it works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant