static TextHitInfo x2RelOffset(TextLayout textLayout, float x) { TextHitInfo hit; x -= EXTRA_MARGIN_WIDTH; if (x >= textLayout.getAdvance()) { hit = TextHitInfo.trailing(textLayout.getCharacterCount()); } else { hit = textLayout.hitTestChar(x, 0); // What about backward bias -> with higher offsets it may go back visually } return hit; }