2011-02-18 135 views

回答

29
int pos = editText.getSelectionStart(); 
Layout layout = editText.getLayout(); 
int line = layout.getLineForOffset(pos); 
int baseline = layout.getLineBaseline(line); 
int ascent = layout.getLineAscent(line); 
float x = layout.getPrimaryHorizontal(pos); 
float y = baseline + ascent; 

並且在那裏獲得遊標的像素中的x,y位置。

0

你可以找到當前選擇的行數和這樣的色譜柱:

// Get the current selection's line number 
int line = edittext.getLayout().getLineForOffset(edittext.getSelectionStart()); 

// Find the index for the start of the selected line. Subtract that from the current selection's index 
int column = edittext.getSelectionStart() - edittext.getLayout().getLineStart(line);