【发布时间】:2015-01-29 20:36:30
【问题描述】:
当父级由列表组成时,Google 的 Material Design 指南为“父级到子级”过渡规定了以下过渡。 (Material Design Guidelines)
如何提供这样的过渡?我不知道为实现这一点而提供的任何内置转换。
【问题讨论】:
当父级由列表组成时,Google 的 Material Design 指南为“父级到子级”过渡规定了以下过渡。 (Material Design Guidelines)
如何提供这样的过渡?我不知道为实现这一点而提供的任何内置转换。
【问题讨论】:
一种选择是使用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 垂直和水平向外扩展
【讨论】:
使用共享元素启动活动
在具有共享元素的两个活动之间制作屏幕过渡动画:
在您的主题中启用窗口内容转换。 在您的样式中指定共享元素过渡。 将您的转换定义为 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()。
【讨论】:
嘿,我想我迟到了几个星期,但我刚刚发布了一个用于构建它的库,灵感来自 Google Inbox:https://github.com/saket/InboxRecyclerView
【讨论】:
您可以使用以下代码制作动画
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 来实现不同的视图过渡动画。
【讨论】: