问题
The TextViews in a RecyclerView and, running following code when the Recyclerview onDown event happen:
@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());
}
}
If the TextView is single line no problem the line order and offset of clicked TextView is happening true values but within multiple line, the line order is happening total line number + 1 of the TextView. If the TextView is multiple lines how to return touched line order of the TextView? (The TextViews has spanners and text size of lines different)
来源:https://stackoverflow.com/questions/62528990/multiple-line-textview-getlineforvertical-returning-wrong-line-order-in-android