检查视窗是否可见的最佳方法是什么?检查视窗是否可见的最佳方法是什么?
我有一个CustomView,它是我的SDK的一部分,任何人都可以将CustomView添加到他们的布局。当我的CustomView定期对用户可见时采取一些操作。因此,如果视图对用户不可见,那么它需要停止定时器,并且当它再次变为可见时,它应该重新开始它的过程。
但不幸的是,没有确定的方式来检查我的CustomView是否对用户可见或不可见。有几件事我可以检查和听:
onVisibilityChange //it is for view's visibility change, and is introduced in new API 8 version so has backward compatibility issue
onWindowVisibilityChange //but my CustomView can be part of a ViewFlipper's Views so it can pose issues
onDetachedFromWindows //this not as useful
onWindowFocusChanged //Again my CustomView can be part of ViewFlipper's views.
因此,如果任何人遇到过这种问题,请投入一些光。每次需要绘制视图时调用
我也不得不这样做[这](http://stackoverflow.com/questions/7781892/own -defined-layout-ondraw-method-not-getting-called/7784369#7784369)为了这个工作 – 2014-08-20 23:21:34