【问题标题】:Android animate view from left to rightAndroid动画视图从左到右
【发布时间】:2017-10-26 07:20:37
【问题描述】:

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

我的观点:

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

【问题讨论】:

  • 你可以使用属性动画或翻译动画。
  • 是属性动画师。只是我不知道如何实现线性效果

标签: java android animation


【解决方案1】:

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

这是将文本视图在 x 轴上移动 100 点的示例代码。 您可以像这样为自己的视图设置动画。

 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/

【讨论】:

  • 仍在尝试。到目前为止还没有成功
  • 我不认为你可以用这个达到我需要的效果。
  • 前进后可以再次后退,这样就可以达到这种效果。
猜你喜欢
  • 1970-01-01
  • 2012-01-30
  • 2011-07-06
  • 1970-01-01
  • 1970-01-01
  • 2021-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多