【问题标题】:How to implement the "parent-to-child" navigational transition as prescribed by Material Design如何实现 Material Design 规定的“父子”导航过渡
【发布时间】:2015-01-29 20:36:30
【问题描述】:

当父级由列表组成时,Google 的 Material Design 指南为“父级到子级”过渡规定了以下过渡。 (Material Design Guidelines)

如何提供这样的过渡?我不知道为实现这一点而提供的任何内置转换。

【问题讨论】:

    标签: android material-design


    【解决方案1】:

    一种选择是使用ActivityOptionsCompat.makeScaleUpAnimation

    Activity activity = getActivity();
    Intent intent = new Intent(activity, OtherActivity.class);
    Bundle options = ActivityOptionsCompat.makeScaleUpAnimation(
        sourceView, 0, 0, sourceView.getWidth(), sourceView.getHeight()).toBundle();
    
    ActivityCompat.startActivity(activity, intent, options);
    

    这将导致新活动从您的sourceView 垂直和水平向外扩展

    【讨论】:

    • 如何反转,我的意思是按下后退键时如何应用?
    • 以及如何调整速度?
    【解决方案2】:

    使用共享元素启动活动

    在具有共享元素的两个活动之间制作屏幕过渡动画:

    在您的主题中启用窗口内容转换。 在您的样式中指定共享元素过渡。 将您的转换定义为 XML 资源。 使用 android:transitionName 属性为两个布局中的共享元素分配一个通用名称。 使用 ActivityOptions.makeSceneTransitionAnimation() 方法。

    // get the element that receives the click event
    final View imgContainerView = findViewById(R.id.img_container);
    
    // get the common element for the transition in this activity
    final View androidRobotView = findViewById(R.id.image_small);
    
    // define a click listener
    imgContainerView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(this, Activity2.class);
            // create the transition animation - the images in the layouts
            // of both activities are defined with android:transitionName="robot"
            ActivityOptions options = ActivityOptions
                .makeSceneTransitionAnimation(this, androidRobotView, "robot");
            // start the new activity
            startActivity(intent, options.toBundle());
        }
    });
    

    对于您在代码中生成的共享动态视图,请使用 View.setTransitionName() 方法在两个活动中指定一个通用元素名称。

    要在完成第二个 Activity 时反转场景过渡动画,请调用 Activity.finishAfterTransition() 方法而不是 Activity.finish()。

    从这里Customize Activity Transitions

    【讨论】:

      【解决方案3】:

      嘿,我想我迟到了几个星期,但我刚刚发布了一个用于构建它的库,灵感来自 Google Inbox:https://github.com/saket/InboxRecyclerView

      【讨论】:

      • 很高兴能够在这么多年后标记一个已被接受的答案 - 只有能够理解和处理所有过渡复杂性的解决方案。
      【解决方案4】:

      您可以使用以下代码制作动画

      Intent intent = new Intent(MainActivity.this, NFCTagInformationActivity.class);
      Bundle options = ActivityOptionsCompat.makeClipRevealAnimation(
                  cvTagInfoSmall, 0, 0, cvTagInfoSmall.getWidth(), cvTagInfoSmall.getHeight()).toBundle();
      ActivityCompat.startActivity(this, intent, options);
      

      您可以使用makeScaleUpAnimation 代替makeClipRevealAnimation 来实现不同的视图过渡动画。

      【讨论】:

        猜你喜欢
        • 2019-04-12
        • 2019-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-29
        • 2015-08-26
        相关资源
        最近更新 更多