GetDrawingCache () returned by Bitmap not updated

I have a custom view that will manage hundreds of discrete custom sequential drawing events. Instead of saving a collection of all the individual text, string, formal updates, and then redrawing them all during each onDraw, I grab the canvas bitmap at the end of each onDraw and then run the next onDraw with that bitmap. A description of my problem follows this snippet:

public class TestView extends View implements OnTouchListener {
    private Paint mPaint;
    private Bitmap mPrevCanvas;
    private int mTouchCount = 0;

    float mX = 50f;
    float mY = 50f;

    public TestView(Context context) {
        super(context);
        setFocusable(true);
        setFocusableInTouchMode(true);      
        this.setOnTouchListener(this);
        this.setDrawingCacheEnabled(true);

        mPaint = new Paint();
        mPaint.setTextSize(30f);
    }

    @Override
    protected void onDraw(Canvas canvas) {   

        if (mTouchCount == 0) {
            canvas.drawText("Touch screen to begin", 50f, 100f, mPaint);
        } else {
            if (mPrevCanvas != null) {
                canvas.drawBitmap(mPrevCanvas, 0, 0, mPaint);
            }

            canvas.drawText(Integer.toString(mTouchCount), mX, mY, mPaint);
            mPrevCanvas = getDrawingCache().copy(Bitmap.Config.ARGB_8888, false);
        }
    }

    public boolean onTouch(View arg0, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            mX = event.getX();
            mY = event.getY();
            mTouchCount += 1;
            invalidate();
        }
        return true;
    }
}

, , mPrevCanvas . , getDrawingCache(), getDrawingCache , , , , -, .

"1". "1" . , Bitmap mPrevCanvas ( "1" ), , (, "2", "3" ..) mPrevCanvas onDraw, , onDraw , ... - mPrevCanvas , -, ( "1" ).

() , isDrawingCacheEnabled() - onDraw; () destroyDrawingCache() buildDrawingCache() ; (c) mPrevCanvas null getDrawingCache(), , ; (d) O'Reilly Java , , , Java, Android API.

Q1: getDrawingCache() Bitmap, canvas.drawText, - drawText?

Q2: , , - ?

+4
1

, , - , .

( )

+1

All Articles