使用滚动时在TextView中获取触摸坐标 [英] Get touch coordinates in TextView when using scrolling

查看:278
本文介绍了使用滚动时在TextView中获取触摸坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一个TextView算出触摸位置,并计算出它的性格所抵消。
我使用

I need to calculate the touch location on a TextView and calculate it's character offset. I'm using

int line = layout.getLineForVertical(event.getY());
int characterOffset = layout.getOffsetForHorizontal(line , event.getX());

在一个TextView OnTouchListener 来获得触摸坐标,并将其转换为字符当前的TextView 偏移。它完美并给该被点击的字符的位置。
但是,当我使用的方法: textView.setMovementMethod(新ScrollingMovementMethod()); 来主动滚动的的TextView ,前运算计算出触摸位置将不再工作,因为它无法计算滚动的行并审查的TextView的开始协调联系。
我怎样才能解决这个问题,是有没有办法获取滚动值?

in a TextView OnTouchListener to get the touch coordinates and convert it to a character offset in the current TextView. It works perfectly and give the place of the character which is clicked. But when I'm using method: textView.setMovementMethod(new ScrollingMovementMethod()); to active scrolling for the TextView , the former operations to calculate the touch location would not work anymore because it can't calculate the scrolled lines and consider the touch coordinated from the beginning of the TextView. How can I fix this and is there any way for getting scrolled value?

推荐答案

使用

View.getScrollX() and/or View.getScrollY()

这篇关于使用滚动时在TextView中获取触摸坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆