问题
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