EditText 較大,需獲取光標相對於整個螢幕的絕對坐標 (X, Y)。
int[] location = new int[2]; editText.getLocationOnScreen(location); 得到左上角 (x, y)。Layout layout = editText.getLayout(); int cursorOffset = layout.getPrimaryHorizontal(editText.getSelectionStart()); int lineTop = layout.getLineTop(editText.getSelectionStart());(location[0] + cursorOffset, location[1] + lineTop)。CSDN 博客完整示例:Android 獲取 EditText 光標絕對坐標