Draw background of custom View from .png file on Android

前端 未结 2 1783
滥情空心
滥情空心 2021-01-13 03:16

I created a custom View by extending from View. In onDraw() I managed to draw some circles and other stuff. But now I want to add a background from a resource (sd card or a

2条回答
  •  甜味超标
    2021-01-13 04:11

    I'm afraid that you get OutOfMemoryError, cause onDraw is called many times during view lifecycle, and every time you are allocating memory for new bitmap. Just make bg member (maybe - static) of your class and load it only once - in your view's constructor. And don't forget to recycle bitmap on view's detaching.

提交回复
热议问题