Android - drawing cache - when is it useful?
I am reading about setDrawingCacheEnabled
and getDrawingCache
and I was wondering when is it good to use it or when its not good.
Basically in my case I have an HorizontalScrollView
with many things inside it so its scrolls left/right and most of the things are not visible.
If I use setDrawingCacheEnabled(true)
on the views, does it help? or this is only when I use custom views and I call getDrawingCache()
?
Is there any other 'cache' way to use开发者_如何学编程 in a HorizontalScrollView
?
TouchInterceptor.java - This is class responsible for reordering your playlist in the default music player. It uses setDrawingCacheEnabled
when you start dragging the current view. Basically, it creates a bitmap from the ListView
item and drag it. Take a closer look at onInterceptTouchEvent
method.
It's definitely useful for screenshots as Marcel said. It is also very useful performance-wise, as that is what it was created for. It does use up more memory, as you render the view into a bitmap first.
What you do is, you setDrawingCacheEnabled
to true
, call getDrawingCache
which returns a bitmap and store this bitmap. In onDraw
, you do draw the bitmap you got if the cache is on, or the view otherwise. This can be very nice when scrolling.
精彩评论