怎样才能获得图像的X和Y位置的android上的onCreate? [英] How can get x and y position of an image in android on onCreate?

查看:203
本文介绍了怎样才能获得图像的X和Y位置的android上的onCreate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想当前的 X'放大器;是合作的ImageView的对的onCreate 活动坐标,是有相同的解决方案?请分享你在同样的想法。

I want current X & Y co ordinates of an ImageView on onCreate of Activity, is there any solution for the same ? Please share your idea on same.

推荐答案

其实,当你调用的setContentView() Android的概括开始的意见拉丝表面,你可以观察使用 viewTrewwObserve 所以,你不能让的ImageView 的高度和宽度的onCreate ()作为其目前不画呢。

Actually, when you call setContentView() the Android nutshell starts the views drawing on surface, Which you can observe on using viewTrewwObserve So you can not get the height and width of ImageView in onCreate() as its not currently draw yet.

您可以使用,(没试过)

You can use, (Not tried)

imageView.getViewTreeObserver().addOnGlobalLayoutListener(
 new ViewTreeObserver.OnGlobalLayoutListener() {
  @Override
  public void onGlobalLayout() {
    // Get ImageView height width here <------------
  }
});

这将注册一个回调函数被调用时,全球布局状态或视图树内的变化的观点的知名度。

It will Register a callback to be invoked when the global layout state or the visibility of views within the view tree changes.

更新:

或者你可以使用<一个href=\"http://developer.android.com/reference/android/app/Activity.html#onWindowFocusChanged%28boolean%29\"相对=nofollow> onWindowFocusChanged(布尔hasFocus)

Or you can use onWindowFocusChanged (boolean hasFocus).

这是该活动是否是对用户可见的最佳指标。默认实现清除键跟踪状态,所以应该总是被调用。

This is the best indicator of whether this activity is visible to the user. The default implementation clears the key tracking state, so should always be called.

这篇关于怎样才能获得图像的X和Y位置的android上的onCreate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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