要在窗口获得焦点以后再去获取控件在屏幕上的绝对坐标,在onCreate或者onResume函数里使用,均得不到实际坐标。
解决方法
<TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="leftTop"android:id="@+id/textView"/>
使用配置属性方法点击回调
public void leftTop(View view) {
int[] location = new int[2];
view.getLocationOnScreen(location);
}