getLocationOnScreen将()中的onCreate()刚刚返回0 [英] getLocationOnScreen() in onCreate() just returns zeroes

查看:1187
本文介绍了getLocationOnScreen将()中的onCreate()刚刚返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个按钮点击响应的ImageView的(或其他视图)调用getLocationOnScreen()给出正确的值。

Calling getLocationOnScreen() on an ImageView (or other View) in a response to a button click gives correct values.

但调用getLocationOnScreen()的活动:在OnCreate()的时候,我只得到[0,0]。我该如何解决这个问题?

But when calling getLocationOnScreen() from Activity::onCreate(), I only get [0, 0]. How can I fix this?

时的onCreate()太早了所有的计算工作要做?有没有以后更好的地方勾开始动画?

Is onCreate() too early for all calculations to be done? Is there a later better place to hook to start animations?

推荐答案

还为时过早检查 getLocationOnScreen将()的onCreate()。更好的地方是在视图级(如果您使用的是自定义视图),是 onLayout()。只有在这里,视图的大小和位置进行了计算。如果,你是不是创建自定义视图,您可在活动水平 onWindowFocusChanged得到它()(具有焦点的活动)。

It's too early to check for getLocationOnScreen() in onCreate(). The better place is at view level (if you are using custom views), is at onLayout(). Only here, the view's size and position are calculated. In case, you aren't creating custom views, you could obtain it in activity level at onWindowFocusChanged() (with the activity having the focus).

这篇关于getLocationOnScreen将()中的onCreate()刚刚返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆