TextBoundsInfo.GetOffsetForPosition(Single, Single) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Return the index of the closest character to the given position.
[Android.Runtime.Register("getOffsetForPosition", "(FF)I", "", ApiSince=34)]
public int GetOffsetForPosition (float x, float y);
[<Android.Runtime.Register("getOffsetForPosition", "(FF)I", "", ApiSince=34)>]
member this.GetOffsetForPosition : single * single -> int
Parameters
- x
- Single
the x coordinates of the interested location, in the editor's coordinates.
- y
- Single
the y coordinates of the interested location, in the editor's coordinates.
Returns
the index of the character whose position is closest to the given location. It will return -1 if it can't find a character.
- Attributes
Remarks
Return the index of the closest character to the given position. It's similar to the text layout API Layout#getOffsetForHorizontal(int, float)
. And it's mainly used to find the cursor index (the index of the character before which the cursor should be placed) for the given position. It's guaranteed that the returned index is a grapheme break. Check #getGraphemeSegmentFinder()
for more information.
It's assumed that the editor lays out text in horizontal lines from top to bottom and each line is laid out according to the display algorithm specified in unicode bidirectional algorithm.
This method won't check the text ranges whose line information is missing. For example, the TextBoundsInfo
's range is from index 5 to 15. If the associated SegmentFinder
only identifies one line range from 7 to 12. Then this method won't check the text in the ranges of [5, 7) and [12, 15).
Under the following conditions, this method will return -1 indicating that no valid character is found: <ul> <li> The given y
coordinate is above the first line or below the last line (the first line or the last line is identified by the SegmentFinder
returned from #getLineSegmentFinder()
). </li> <li> There is no character in this TextBoundsInfo
. </li> </ul>
Java documentation for android.view.inputmethod.TextBoundsInfo.getOffsetForPosition(float, float)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.