如何知道什么时候活动结束一个布局传递? [英] How to know when an activity finishes a layout pass?

查看:118
本文介绍了如何知道什么时候活动结束一个布局传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个后台线程来更新我的活动的用户界面,在的onCreate()。它可以被添加的布局,或改变其他的尺寸。

I have a background thread that updates the UI of my activity, after the onCreate(). It can be adding layouts, or changing the size of others.

我只是希望在布局传递在我的活动结束后进行检测,以便能够手动更新的观点强加于人直接取决于刚刚阿迪或修改的布局位置。

I simply want to detect when the layout pass is finished in my activity, to be able to manually update the positions of others views that directly depend on the layouts that were just adde or modified.

现在,我只是用一个处理程序 postDelayed可运行,做后小延时工作, ,在modifs后,各地50-100毫秒触发 requestLayout()

For now, I just use a Handler with a postDelayed runnable that does the job, after a small delay, around 50-100 ms after the modifs that triggers the requestLayout().

它的工作原理,但我们可以明显看到的延迟。我想尽快完成这项工作。在视图code很简单,检测计量合格,但我不觉得如何,直接在活动解决这个问题。

It works, but we can obviously see the delay. I would like to do the job as soon as possible. In a view code it's simple to detect the measurement pass, but I don't find how to solve this directly in the activity.

推荐答案

一个GlobalLayoutListener会开火的布局完成的事件。那会满足您的需求?

A GlobalLayoutListener will fire an event on completion of a layout. Would that suit your needs?

View myView=findViewById(R.id.myView);
  myView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                //At this point the layout is complete and the 
                //dimensions of myView and any child views are known.
            }
        });

这篇关于如何知道什么时候活动结束一个布局传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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