Android Canvas save和restoreToCount
@Override public void draw(Canvas canvas) { if (mDrawable!=null) { int sc=canvas.save(); if (mAnimation!=null) { mAnimation.getTransformation( AnimationUtils.currentAnimationTimeMillis(), mTransformation); canvas.concat(mTransformation.getMatrix()); } mDrawable.draw(canvas); canvas.restoreToCount(sc); } }
canvas.save()和canvas.restoreToCount(sc);是用来保存和回复Canvas的状态(Maxtrix等属性),因为我们需要修改Canvas的Matrix属性,canvas.concat方法都会和当前Canvas的Matrix进行矩阵运算,如果我们不保存之前的Matrix属性,每次都会跟上次矩阵运算的结果相乘,对应本例来说,每次平移的距离会越来越大。
转:http://blog.csdn.net/gaomatrix/article/details/6525240