Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要从 View 的方法中得到正确的坐标。getLocationOnScreen (locationOnScreen)。但是在 View.onCreate() 方法中创建了视图。我可以通过什么方法获得视图相对于 Activity 的正确位置?
final ViewTreeObserver vto = myView.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { public void onGlobalLayout() { // ... vto.removeGlobalOnLayoutListener(this); } }
来自:我如何在我的活动中测量所有视图的时刻?