Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 579
user1654627 Avatar asked Dec 06 '22 12:12

user1654627


1 Answers

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.

like image 86
Andro Selva Avatar answered Jan 12 '23 21:01

Andro Selva