2011-02-18 11 views

Répondre

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; 

et il vous obtenez les positions x, y en pixels du curseur.

+0

Cela a été une aide énorme que je travaille sur cette question: http://stackoverflow.com/questions/25036816/custom-rotated-edittext-view-with-working-selection-cursor-location-etc – Suragch

0

Vous trouverez le numéro de sélection en cours ligne et de colonne comme ceci:

// 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); 
Questions connexes