9
如何在Android中的EditText
中获取光标位置x,y? (其中x是行#并且y是列#)如何在EditText中获取光标位置(x,y)android
如何在Android中的EditText
中获取光标位置x,y? (其中x是行#并且y是列#)如何在EditText中获取光标位置(x,y)android
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位置。
你可以找到当前选择的行数和这样的色谱柱:
// 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);
你说的(X,Y),参考一光标是什么意思? (行号,列#)? – Devunwired 2011-02-18 17:28:18
是的,我想要得到游标(Line#,Column#)。你可以帮我吗? – hieubk 2011-02-19 01:57:34