【问题标题】:MvxFragment enter animationMvxFragment 进入动画
【发布时间】:2020-11-05 14:58:57
【问题描述】:

我想在MVVMCross项目中实现导航时进入退出片段动画。

[MvxFragmentPresentation(typeof(TestViewModel), 
        Resource.Id.content_frame, true,
        Resource.Animation.enter_from_right,
        Resource.Animation.exit_nothing_animation)]

enter_from_right

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
  <translate
     android:fromXDelta="100%p" android:toXDelta="0%"
     android:fromYDelta="0%" android:toYDelta="0%"
     android:duration="@android:integer/config_mediumAnimTime" />
</set>

exit_nothing_animation

<?xml version="1.0" encoding="UTF-8" ?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="300"
    android:fromAlpha="1"
    android:toAlpha="1" />

我希望新片段从旧 frgamnet 的右侧滑过,旧片段将保留在同一个地方。

但是新片段只是立即出现,没有动画

其他主题建议使用 Add insted Replace,但 MVVMCross 项目中的正确方法是什么?

【问题讨论】:

    标签: android xamarin mvvmcross


    【解决方案1】:

    答案是在基片段类中重写此方法

    public override Animation OnCreateAnimation(int transit, bool enter, int nextAnim)
            {
                if (nextAnim == Resource.Animation.enter_from_right)
                {
                    ViewCompat.SetTranslationZ(view, 1f);
                }
                else
                {
                    ViewCompat.SetTranslationZ(view, 0f);
                }
    
    
                return base.OnCreateAnimation(transit, enter, nextAnim);
            }
    

    【讨论】:

    • 感谢您的分享,请采纳您的回答,这将对有类似问题的其他人有所帮助。
    猜你喜欢
    • 2014-10-11
    • 2015-03-11
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 1970-01-01
    相关资源
    最近更新 更多