2011-02-18 265 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);