Android TextViewは、ある文字の座標を取得します.
882 ワード
TextView
では、Layout
によって文字が管理される位置/**
* TextView
*
* @parms tv
* @parms index
* @return
*/
private int getTextViewSelectionBottomY(TextView tv,int index) {
Layout layout = tv.getLayout();
Rect bound = new Rect();
int line = layout.getLineForOffset(index);
layout.getLineBounds(line, bound);
int yAxisBottom = bound.bottom;// y
// int yAxisTop = bound.top;// y
// float xAxisLeft = layout.getPrimaryHorizontal(index);// x
// float xAxisRight = layout.getSecondaryHorizontal(index);// x
return yAxisBottom;
}
なお、取得されたこの座標は
TextView
の相対座標である.TextView.getScrollY()
によってtextview
に示されている内容の一番上の行の座標を取得することができ、そうすると現在の文字列のスクリーン上の座標位置を算出することができます.