Moving Circle on Live Wallpaper

妖精的绣舞 提交于 2019-12-06 15:31:23

SOLVED: finally i got the solution by not concentrating on removing circle but drawing bitmap again and again with new point. The method is as follows:

{
BitmapFactory.Options options = new BitmapFactory.Options();
                options.inPurgeable = true;
                bitmap =  BitmapFactory.decodeResource(getResources(),
                        R.drawable.aquarium, options);
Paint paint = new Paint();

/**
     * Method to move circle i.e to draw bitmap with new circle position.
     * 
     * @param x
     * @param y
     */
    private void renderBackground(int x, int y) {

        Log.d("x==" + x, "y==" + y);


         surfaceHolder = getSurfaceHolder();
        Canvas canvas = null;
        try {
            canvas = surfaceHolder.lockCanvas();

            if (canvas != null) {
                paint.setColor(Color.RED);

                canvas.save();

                // set Back ground


                canvas.drawBitmap(bitmap, 0, 0, null);

                // write draw circle.
                 paint.setAntiAlias(true);
                 canvas.drawCircle(x, y, 15, paint);

                canvas.restore();

                bitmap.recycle();

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        finally {
            if (canvas != null) {
                surfaceHolder.unlockCanvasAndPost(canvas);
                // showWallpaper();
            }
        }
        animHandler.removeCallbacks(animRunnable);
        if (isVisible()) {
            animHandler.postDelayed(animRunnable, 1000L / 25L);
        }
    }


}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!