【问题标题】:Element Animation/Transition Between Multiple Views not between activity or fragment多个视图之间的元素动画/过渡不在活动或片段之间
【发布时间】:2020-09-27 09:23:54
【问题描述】:

我是 android 动画/过渡的新手,我想制作一个动画,如下所示:

我应该如何做到这一点?

【问题讨论】:

    标签: android animation transition


    【解决方案1】:

    你有多项选择:

    您可以使用此库进行两种类型的转换

    1. 使用TransitionManager.go()。在这种情况下,您应该创建两个scene 并在这两个场景之间切换。 所有需要的动画都将由过渡管理器处理。更多信息请阅读this 链接

    示例:

     Scene aScene;
     Scene anotherScene;
    
     // Create the scene root for the scenes in this app
     sceneRoot = (ViewGroup) findViewById(R.id.scene_root);
    
     // Create the scenes
     aScene = Scene.getSceneForLayout(sceneRoot, R.layout.a_scene, this);
     anotherScene =
        Scene.getSceneForLayout(sceneRoot, R.layout.another_scene, this);
     //transition from root scene to another scene
     TransitionManager.go(anotherScene);
    
    1. 使用TransitionManager.beginDelayedTransition(rootView)。在这种情况下,您可以在paren 上设置beginDelayTransition,所有直接子级将在布局属性更改时设置动画。更多信息请阅读this 链接

    示例:

    // Get the root view and create a transition
    rootView = (ViewGroup) findViewById(R.id.mainLayout);
    mFade = new Fade(Fade.IN);
    
    // Start recording changes to the view hierarchy
    TransitionManager.beginDelayedTransition(rootView, mFade);
    
    // change in one of rootView childs
    childView.setWidth(100);
    
    // When the system redraws the screen to show this update,
    // the framework will animate the addition as a fade in
    
    • 使用MotionLayout。欲了解更多信息,请阅读链接。
    • 在您的情况下,您也可以使用viewPager。您可以创建两个片段第一个使用键盘输入价格,第二个输入“for”,其余视图保留在父级中。然后在标题中点击价格的这两个片段之间切换viewPager,您还需要根据当前片段淡入/淡出标题价格和“取消”按钮。您将看到类似您的 gif 的内容。

    【讨论】:

    • 感谢您的回答。如何在视图寻呼机内向片段添加过渡?以及如何处理fragment和父fragment之间的通信?
    【解决方案2】:

    你可以试试Motion Editor

    如需更深入的研究,请尝试 Youtube 上的一些视频教程。

    【讨论】:

      猜你喜欢
      • 2011-06-23
      • 2015-04-07
      • 1970-01-01
      • 2012-03-24
      • 1970-01-01
      • 2011-09-01
      • 2015-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多