How to understand that android finished drawing a view? [duplicate]

こ雲淡風輕ζ 提交于 2019-12-10 20:40:30

问题


Possible Duplicate:
When has the Activity finished drawing itself?

I want to know when a view completes its drawing, is that possible? How can I understand if android finished drawing a view or not?


回答1:


Add a ViewTreeObserver to it.

Sample,

      TextView pagerView1=new TextView(this);
   ViewTreeObserver textViewTreeObserver=pagerView1.getViewTreeObserver();
        textViewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            public void onGlobalLayout() {

                           //Do your operations here. 

                    pagerView1.removeGlobalOnLayoutListener(this);



            }
        });

This is a Listener which gets called once that particular gets drawn completely. So I have made it use for TextView. Similarly you can make use of any view you do. And inside onGlobalLayout() you can do your code.



来源:https://stackoverflow.com/questions/12477026/how-to-understand-that-android-finished-drawing-a-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!