0

I am trying to make an animation to my custom view. But when i start my app, my custom view did not come with animation.

I have try some code from some article. And it work but when when i did myself it freezing. I also tried some code from this site , and also did not come with animation.

here my code

class MyView extends LinearLayout
       {

private float powerPos;
private RectF rect;
private Paint paint;


GameView(Context ctx){
    super(ctx);
    init();
    setBackgroundColor(Color.BLUE);
}

public void drawPower(float i){
    powerPos = i;
}

private void init(){
    rect = new RectF(100, 100, 400, 400);
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);
    paint.setStyle(Paint.Style.STROKE);
    paint.setTextSize(70);
    paint.setTypeface(Typeface.MONOSPACE);

}





@Override
protected void onDraw(Canvas canvas)
{

  canvas.drawText("i am tge power",powerPos,rect.centerY(),paint);


    super.onDraw(canvas);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
}

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();




}

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
}


private void animateArch() {
    final android.animation.ValueAnimator frontEndExtend = android.animation.ValueAnimator.ofFloat(0, 500);
    frontEndExtend.setDuration(5000);
    frontEndExtend.setInterpolator(new android.view.animation.LinearInterpolator());
    frontEndExtend.addUpdateListener(new android.animation.ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(android.animation.ValueAnimator animation) {


            }
        });
    frontEndExtend.start();
    frontEndExtend.addListener(new android.animation.ValueAnimator.AnimatorListener() {
            @Override
            public void onAnimationStart(android.animation.Animator animator) {
                float value = ((Float) (frontEndExtend.getAnimatedValue())).floatValue();
                powerPos = value;
            }

            @Override
            public void onAnimationEnd(android.animation.Animator  animator) {
                animateArch();
            }

            @Override
            public void onAnimationCancel(android.animation.Animator  animator) {

            }

            @Override
            public void onAnimationRepeat(android.animation.Animator  animator) {

            }
        });
}}

did I left something?

shahril772
  • 53
  • 6
  • Well, you got at least two problems there: first, you're not calling the animateArch() method anywhere in your code, and second, you're doing nothing inside onAnimationUpdate(), which is where you're supposed to actually make the animation magic... – Tharkius Jun 04 '18 at 20:06
  • Possible duplicate of [Android: animated custom views](https://stackoverflow.com/questions/42763616/android-animated-custom-views) – Willian Soares Jun 04 '18 at 20:06

0 Answers0