1

I am making an animated tutorial for the application. I am using a fragment over the activity to show image view sliding effect. I am using Translate animation to move the image view to the specific view to describe its working, but actually I want to animate the image view to move infinite times after reaching to the view.

  • chek [this](http://developer.android.com/guide/topics/graphics/view-animation.html) – Iamat8 Oct 26 '15 at 10:45
  • Check This--> http://stackoverflow.com/questions/2032304/android-imageview-animation http://www.javasrilankansupport.com/2013/06/how-to-move-an-image-from-left-to-right-and-right-to-left-in-android.html http://stackoverflow.com/questions/16399630/infinite-animation-of-imageview-android – Chaudhary Amar Oct 26 '15 at 10:52

1 Answers1

1

Assume that view v is suppose to animate

    public void ViewExapand(View v)
        {
                        v.setVisibility(View.VISIBLE);

                        final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                        final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
                        v.measure(widthSpec, heightSpec);
                        ValueAnimator mAnimator = slideAnimator(0, v.getMeasuredHeight(),v);
                        mAnimator.start();
        }



private ValueAnimator slideAnimator(int start, int end, final View v)
    {
        ValueAnimator animator = ValueAnimator.ofInt(start, end);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                //Update Height
                int value = (Integer) valueAnimator.getAnimatedValue();
                ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
                layoutParams.height = value;
                v.setLayoutParams(layoutParams);
            }
        });
        return animator;
    }

You can also use ObjectAnimator

ObjectAnimator.ofInt(your view, "left", 100, 250)
    .setDuration(250)
    .start();
Amol Patil
  • 491
  • 4
  • 9