Bartos
Bartos

Reputation: 1037

Android animate view from left to right

I have draw view. It's a place where user can make a signature. When user click button I want to make some kind of scanner effect - draw view background will change from left to right side ("progress" of scanning). Right now I created an animation but it changes whole whole background in one time. I need to make it linear - from left to right. Any idea how to achieve this effect ? :)

My View :

 <com.rm.freedrawview.FreeDrawView
        android:id="@+id/draw_layout"
        android:layout_width="400dp"
        android:layout_height="200dp"
        android:background="@drawable/border_background"
        app:paintAlpha="255"
        app:paintColor="@color/black"
        app:paintWidth="2dp"
        app:resizeBehaviour="crop"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="400dp"/>

And this is my animation :

@OnClick(R.id.next_button)
    public void openActivity(){

        int colorFrom = getResources().getColor(R.color.red);
        int colorTo = getResources().getColor(R.color.black);
        ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
        colorAnimation.setDuration(1000);
        colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                mDraw.setBackgroundColor((int) animator.getAnimatedValue());

            }

        });
        colorAnimation.start();
    }

Upvotes: 0

Views: 1829

Answers (1)

Sardar Khan
Sardar Khan

Reputation: 841

You can check this offcial link and animate you view https://developer.android.com/guide/topics/graphics/prop-animation.html

Here is the example code to move a textview in x-axis 100 points. You can animate your own view like this.

 ObjectAnimator animation = ObjectAnimator.ofFloat(textView, "translationX", 100f);
 animation.setDuration(1000);
 animation.start();

Or you can check this post Change multiple properties with single ObjectAnimator?

And here is the complete Tutorial for how to do this. http://androideverywhere.in/translate-scale-rotate-alpha-animations/

Upvotes: 2

Related Questions