开发者

How can I determine if I will draw offscreen when doing custom bitmap blitting in a view inside a scrollview in Android

I have subclassed View and do some bitmap drawing inside of the onDraw method. This view is then placed in a horizontal scrollview. Some of the time the bitmaps will not be visible since they are scrolled off screen. To impr开发者_JAVA百科ove performance I would like to avoid drawing anything when the object will not be visible.

So the question is, how do I determine that my bitmap will be drawn offscreen so I can just return without drawing?


I solved this by:

Rect s = new Rect();
getLocalVisibleRect(s);

// (...)
// Do not draw if outside screen
Rect b = getBounds();
boolean offScreen = b.left > s.right || b.right < s.left || b.top > s.bottom || b.bottom < s.top;
if (!offScreen) {
    // Draw here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜