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