看看几个Paint方法:
getTextBounds()和
measureText.我们可以使用它们来确定TextView中文本的偏移量.确定TextView中的偏移后,我们可以将其添加到TextView本身的位置,以确定文本的屏幕坐标(如果需要).
以下示例在三个TextView中查找文本的边界,并在文本周围绘制一个矩形.矩形包含TextView中文本的(x,y)坐标.
activity_main.xml中
一个简单的演示布局.
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:background="@android:color/holo_blue_light"
android:padding="24dp"
android:text="Hello World"
android:textColor="@android:color/bl