Android从左到右动画视图

时间:2017-10-26 07:20:37

标签: java android animation

我有画视图。它是用户可以签名的地方。当用户点击按钮我想要制作某种扫描效果时 - 绘制视图背景将从左侧变为右侧("进度"扫描)。现在我创建了一个动画,但它一次改变了整个背景。我需要使它成为线性的 - 从左到右。知道如何实现这种效果吗? :)

我的观点:

 <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"/>

这是我的动画:

@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();
    }

1 个答案:

答案 0 :(得分:1)

您可以查看此官方链接并为您查看动画 https://developer.android.com/guide/topics/graphics/prop-animation.html

以下是在x轴100点移动textview的示例代码。 您可以像这样设置自己的视图。

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

或者你可以查看这篇文章 Change multiple properties with single ObjectAnimator?

以下是完整的教程,了解如何执行此操作。 http://androideverywhere.in/translate-scale-rotate-alpha-animations/

相关问题