Привет всем. Пытаюсь сделать медленное рисование линии, а получается наоборот - медленное исчезание. Что делаю не так?
| Код | private static class SampleView extends View { private Paint followingPaint; private Path mPath = new Path(); private PathEffect mEffect; private float mPhase; private PathMeasure pm; private float pmLen; private float fSegmentLen; private static Bitmap bmSprite;
public SampleView(Context context) { super(context); setFocusable(true); setFocusableInTouchMode(true); setBackgroundColor(Color.TRANSPARENT); followingPaint = new Paint(Paint.ANTI_ALIAS_FLAG); followingPaint.setStyle(Paint.Style.STROKE); followingPaint.setStrokeWidth(2); mPath.moveTo(100, 100);
mPath.lineTo(100, 100); mPath.lineTo(300, 100); mPath.lineTo(300, 300); mPath.lineTo(350, 350); pm = new PathMeasure(mPath, false); pmLen = pm.getLength();
if (bmSprite == null) bmSprite = BitmapFactory.decodeResource(getResources(), R.drawable.feed_liked_arrow); fSegmentLen = pm.getLength() / iMaxAnimationStep; }
private static int iMaxAnimationStep = 80; private int iCurStep = 0;
@Override protected void onDraw(Canvas canvas) { mEffect = new DashPathEffect(new float[] { pmLen, pmLen }, -fSegmentLen * iCurStep); if (iCurStep <= iMaxAnimationStep) { iCurStep++; // advance to the next step mPhase -= 8; } Matrix mxTransform = new Matrix(); pm.getMatrix(fSegmentLen * iCurStep, mxTransform, PathMeasure.POSITION_MATRIX_FLAG + PathMeasure.TANGENT_MATRIX_FLAG); mxTransform.preTranslate(-bmSprite.getWidth() + 8, -bmSprite.getHeight() + 6); followingPaint.setPathEffect(mEffect); followingPaint.setColor(Color.BLUE); canvas.drawPath(mPath, followingPaint); invalidate(); } }
|
|