我如何挂钩一个时刻,当所有的观点在我的活动被测量? [英] How do I hook a moment when all views are measured in my Activity?

查看:94
本文介绍了我如何挂钩一个时刻,当所有的观点在我的活动被测量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要后尽快 onResume 来了解一些在我的活动的意见正确的宽度,高度和位置。我在哪里可以把这个code。在我的活动?

I need to know correct widths, heights and positions of some of the views in my Activity ASAP after onResume. Where can I place this code in my Activity?

推荐答案

奇怪的是,我得到重用答案的同一天,我做的:

Oddly, I get to reuse an answer the same day I make it:

您可以在设定全球布局监听器在视图树的 onResume(),做你的diddling在那里。

You could set a global layout listener on the view tree in your onResume() and do your diddling in there.

final ViewTreeObserver vto = myView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

    public void onGlobalLayout() {
        // do layout tweaking based on measurements

        // remove the listener... or we'll be doing this a lot.
        vto.removeGlobalOnLayoutListener(this);
    }
}

这篇关于我如何挂钩一个时刻,当所有的观点在我的活动被测量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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