Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 多行文本查看getLineForVertical在Android中返回错误的行顺序_Java_Android_Android Layout - Fatal编程技术网

Java 多行文本查看getLineForVertical在Android中返回错误的行顺序

Java 多行文本查看getLineForVertical在Android中返回错误的行顺序,java,android,android-layout,Java,Android,Android Layout,当RecyclerView onDown事件发生时,在RecyclerView和中运行以下代码的文本视图: @Override public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { int action = e.getAction() & MotionEvent.ACTION_MASK; TextView childTextView = (TextV

当RecyclerView onDown事件发生时,在RecyclerView和中运行以下代码的文本视图:

@Override
public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
    int action = e.getAction() & MotionEvent.ACTION_MASK;
    TextView childTextView = (TextView) rv.findChildViewUnder(e.getX(), e.getY());
    
    if(action == MotionEvent.ACTION_DOWN) {
        // y-coordinate of clicked point. 
        int y = (int) e.getY() - childTextView.getTotalPaddingTop();
        // line order of clicked textview
        int line = childTextView.getLayout().getLineForVertical(y);
        // character offset of clicked line.
        int offset = childTextView.getLayout().getOffsetForHorizontal(line, e.getX());
    }
}
如果TextView是单行没有问题,则单击的TextView的行顺序和偏移量为真值,但在多行内,行顺序为TextView的总行数+1。如果TextView是多行的,如何返回TextView的行顺序?(文本视图有扳手,行的文本大小不同)