1.通过 onWindowFocusChanged监听
//焦点改变可以获得视图的坐标,或进入多次,的onResume onPasuse也会今进入此回调 @覆盖 公共无效 onWindowFocusChanged(布尔 hasFocus){ 超级 .onWindowFocusChanged(hasFocus); 日志。我(“MainActivity”,“drawChartsView:getX:” + drawChartsView .getX()+ “getY:” + drawChartsView .getY()) }
2.通过ViewTree,添加 OnGlobalLayoutListener监听
//通过ViewTree获取启动是的View坐标,但也会进入多次 drawChartsView .getViewTreeObserver()。addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener(){ @ Override public void onGlobalLayout(){ 日志。我(“MainActivity”,“ViewTreedrawChartsView:getX:” + drawChartsView .getX()+ “getY:” + drawChartsView .getY()); } });