Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 961
Daniel Benedykt Avatar asked Jun 23 '10 15:06

Daniel Benedykt


2 Answers

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.

like image 141
Mojo Risin Avatar answered Nov 15 '22 18:11

Mojo Risin


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.

like image 45
Kevin Read Avatar answered Nov 15 '22 18:11

Kevin Read