int start = strBuilder.getSpanStart(span);int end = strBuilder.getSpanEnd(span);int flags = strBuilder.getSpanFlags(span);final ClickableSpan clickable = new ClickableSpan() { public voID onClick(VIEw vIEw) { gettouchActions(span.getURL()); }};strBuilder.setSpan(clickable,start,end,flags);strBuilder.removeSpan(span);解决方法 CustomMovementMethod必须扩展ScrollingMovementMethod并覆盖ontouchEvent方法.为了增加一些额外空间,您必须在尺寸中定义它并在开始/结束范围中使用它.
@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); int startSpan = off - context.getResources().getDimension(R.dimen.extra_space_start); int endSpan = off + context.getResources().getDimension(R.dimen.extra_space_end); ClickableSpan[] link = buffer.getSpans(startSpan,endSpan,ClickableSpan.class); if (link.length != 0) { if (action == MotionEvent.ACTION_UP) { link[0].onClick(Widget); } else if (action == MotionEvent.ACTION_DOWN) { Selection.setSelection(buffer,buffer.getSpanStart(link[0]),buffer.getSpanEnd(link[0])); } return true; } else { Selection.removeSelection(buffer); }}return super.ontouchEvent(Widget,buffer,event);
}
您可以像这样调用自定义链接移动:
textVIEw.setMovementMethod(new CustomlinkMovementMethod(context));textVIEw.setlinksClickable(true);总结
以上是内存溢出为你收集整理的android – 展开ClickableSpan的触控区域全部内容,希望文章能够帮你解决android – 展开ClickableSpan的触控区域所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)