0
我想从XML动画化我的ImageView。它基本上是从中心positino移动到屏幕的顶部。做到这一点,我使用了一个定时器,每x毫秒发射一个函数。这个函数然后将物体进一步向上移动。它确实有效,但它是滞后的。我正在调试三星S7,所以电源应该不成问题。我猜计时器是非常不准确的。你能告诉我做这件事,而不是这个更好的方法:Xamarin,Android:动画有点迟钝(使用定时器)
public class finalPhoto : Activity
{
private System.Timers.Timer timer;
private ImageView wowThatLooksFantastic;
private float i = 0f;
private int test = 0;
private int NegativeSpeed = 350;
private int frameRate = 17; // 17 = etwa 60fps
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.finalPhoto);
wowThatLooksFantastic = FindViewById<ImageView>(Resource.Id.text_wowthatlooksfantastic);
wowThatLooksFantastic.Click += delegate { StartAnimation(); };
test = Resources.DisplayMetrics.HeightPixels;
}
private void StartAnimation()
{
i = wowThatLooksFantastic.GetY();
CountDown();
}
public void CountDown()
{
timer = new System.Timers.Timer();
timer.Interval = frameRate;
timer.Elapsed += OnTimedEvent;
timer.Start();
}
protected override void OnResume()
{
base.OnResume();
}
public void OnTimedEvent(object sender, System.Timers.ElapsedEventArgs e)
{
i -= (test/NegativeSpeed);
wowThatLooksFantastic.SetY(i);
if (wowThatLooksFantastic.GetY() <= 50) // Endposition
{
timer.Stop();
}
}
}
谢谢!我会在下周给它一个镜头!我会报告回来! :) – MrMee
希望这可以帮助,如果你有更多的问题,请写:) – Merian
这工作出色。我的提示:使用这个插值器:android:interpolator =“@ android:anim/accelerate_decelerate_interpolator”它会使动画看起来更流畅! – MrMee