项目中用到了缩放,但是没一点缩放就会重绘,导致放大过程非常的卡。老大说View有一个setDrawingCacheEnabled方法可以防止卡顿,listview就是这么处理的。以下:
setDrawingCacheEnabled
void setDrawingCacheEnabled (boolean enabled)
Enables or disables the drawing cache. When the drawing cache is enabled, the next call to getDrawingCache()
or buildDrawingCache()
will draw the view in a bitmap. Calling draw(android.graphics.Canvas)
will not draw from the cache when the cache is enabled. To benefit from the cache, you must request the drawing cache by calling getDrawingCache()
and draw it on screen if the returned bitmap is not null.
Enabling the drawing cache is similar to setting a layer
when hardware acceleration is turned off. When hardware acceleration is turned on, enabling the drawing cache has no effect on rendering because the system uses a different mechanism for acceleration which ignores the flag. If you want to use a Bitmap for the view, even when hardware acceleration is enabled, see setLayerType(int, android.graphics.Paint)
for information on how to enable software and hardware layers.
This API can be used to manually generate a bitmap copy of this view, by setting the flag to true
and calling getDrawingCache()
.
Parameters | |
---|---|
enabled | boolean : true to enable the drawing cache, false otherwise |