如何理解android完成绘制视图?(How to understand that android finished drawing a view? [duplicate])
可能重复: 活动何时完成绘图本身?
我想知道一个视图何时完成其绘图,这是可能的吗? 我如何理解android是否完成了绘制视图?
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?
最满意答案
添加一个ViewTreeObserver到它。
样品,
TextView pagerView1=new TextView(this); ViewTreeObserver textViewTreeObserver=pagerView1.getViewTreeObserver(); textViewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { public void onGlobalLayout() { //Do your operations here. pagerView1.removeGlobalOnLayoutListener(this); } });这是一个Listener,一旦被完全绘制,就会被调用。 所以我已经将它用于TextView。 同样,您可以使用您所做的任何视图。 在onGlobalLayout()里面你可以做你的代码。
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.
更多推荐
发布评论