2017-02-18 106 views
0

所以我有这几行代码,我尝试做一个动画循环。不幸的是,只有在事件停止时才触发一次。你能帮我么?Xamarin AnimationEnd触发事件只有一次

ImageView imgView1 = FindViewById<ImageView>(Resource.Id.falling_stars1); 
ImageView imgView2 = FindViewById<ImageView>(Resource.Id.falling_stars2); 

Android.Animation.ObjectAnimator animator1 = Android.Animation.ObjectAnimator.OfFloat(imgView1, "y", -700, 100); 
Android.Animation.ObjectAnimator animator2 = Android.Animation.ObjectAnimator.OfFloat(imgView2, "y", 100, 900); 

animator1.SetDuration(2000); 
animator2.SetDuration(2000); 
animator1.Start(); 
animator2.Start(); 

animator1.AnimationEnd += delegate 
{ 
    animator1.Start(); 
}; 

animator2.AnimationEnd += delegate 
{ 
    animator2.Start(); 
}; 

回答

0

RepeatMode: Defines the animation behavior when it reaches the end and the repeat count is greater than 0 or infinite.

Android.Animation.ObjectAnimator animator1 = Android.Animation.ObjectAnimator.OfFloat(imgView1, "y", -700, 100); 
animator1.SetDuration(2000); 
animator1.RepeatCount = ValueAnimator.Infinite; 
animator1.RepeatMode = ValueAnimatorRepeatMode.Restart; 
+0

添加的你在这里提出更改的说明。 –

+0

我可以编辑动画以便它结束并突然出现星星吗?如果有这样做的另一种方式? –

+0

你是什么意思,突然结束并开始?你想让它停止中间动作吗? – Zroq