如何理解android完成绘制视图?(How to understand that android finished drawing a view? [duplicate])

编程入门 行业动态 更新时间:2024-10-27 00:33:24
如何理解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.

更多推荐

本文发布于:2023-07-21 09:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1208969.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   understand   android   finished   duplicate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!