[英]Android animate view from left to right
我有视图。 这是用户可以签名的地方。 当用户单击按钮时,我想产生某种扫描仪效果-绘图视图背景将从左到右变化(扫描的“进度”)。 现在,我创建了一个动画,但是它一次可以改变整个背景。 我需要使其线性-从左到右。 知道如何实现这种效果吗? :)
我的观点 :
<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();
}
您可以检查此官方链接并设置动画,以查看https://developer.android.com/guide/topics/graphics/prop-animation.html
这是在x轴上移动textview 100点的示例代码。 您可以像这样为自己的视图设置动画。
ObjectAnimator animation = ObjectAnimator.ofFloat(textView, "translationX", 100f);
animation.setDuration(1000);
animation.start();
或者,您也可以查看此文章 用单个ObjectAnimator更改多个属性?
这是有关如何执行此操作的完整教程。 http://androideverywhere.in/translate-scale-rotate-alpha-animations/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.