StartAnimation()在Fragment Xamarin Android内部不起作用

问题描述 投票:0回答:1

我有一种情况,希望为Android.Support.V4.App.Fragment的某些元素设置动画。我的片段在MainActivity内部创建,如下所示,并注入到FrameLayout

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    SetContentView(Resource.Layout.activity_main);

    var activeFragment = new TapAnswerFragment();
    var fragmentTx = SupportFragmentManager.BeginTransaction();

    fragmentTx.Add(Resource.Id.answerFragmentFrameLayout, activeFragment);
    fragmentTx.Commit();
}

TapAnswerFragment内部,我有一个点击处理程序:

AlphaAnimation translationFadeIn = new AlphaAnimation(0.5f, 1.0f);

private void TapAnswerRelativeLayout_Click(object sender, System.EventArgs e)
{
    tapAnswerTextView.StartAnimation(translationFadeIn);
}

触发事件后,动画将不会发生。是否可以在片段内运行动画?

java c# android android-fragments xamarin.android
1个回答
0
投票

答案是肯定的。在上面的代码中,您只是忘记设置动画的持续时间。

AlphaAnimation translationFadeIn = new AlphaAnimation(0.5f, 1.0f);

private void TapAnswerRelativeLayout_Click(object sender, System.EventArgs e)
{
   translationFadeIn.Duration = 2000;// Animation duration,Milliseconds in units
   tapAnswerTextView.StartAnimation(translationFadeIn);
}
© www.soinside.com 2019 - 2024. All rights reserved.