Android Material 设计过渡
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24996723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Material design transitions
提问by Diolor
I want to replicate the transitions as explained in Material design by Google. This is the link for the preview, but basically the videos I care about are those two:
我想复制谷歌材料设计中解释的过渡。这是预览的链接,但基本上我关心的视频是这两个:
- http://material-design.storage.googleapis.com/videos/animations-meaningfultransitions-hierarchical_transitions_topLevel_large_xhdpi.webm
- http://material-design.storage.googleapis.com/videos/animation-meaningfultransitions-view_contact_large_xhdpi.webm
- http://material-design.storage.googleapis.com/videos/animations-meaningfultransitions-hierarchical_transitions_topLevel_large_xhdpi.webm
- http://material-design.storage.googleapis.com/videos/animation-meaningfultransitions-view_contact_large_xhdpi.webm
My question is what is the container of the UI? Is this a new Activity which onCreate has animations for each element or is it a fragment?
我的问题是 UI 的容器是什么?这是一个新的 Activity,它的 onCreate 为每个元素都有动画还是一个片段?
In particular on the second example there is some movement on the 1st Activity so inside the onClick is there an animation which also creates a 2nd activity? (note that the clicked name also moves, so this should not be a new activity)
特别是在第二个示例中,第一个活动有一些移动,所以在 onClick 内部是否有动画也创建了第二个活动?(注意被点击的名字也会移动,所以这应该不是一个新的活动)
In other words what the layout (+Activities, fragments) should be if I want to replicate this?
换句话说,如果我想复制这个布局(+活动,片段)应该是什么?
采纳答案by sagus_helgy
Maybe too late but I have found support library contains ActivityOptionsCompat
: https://developer.android.com/reference/android/support/v4/app/package-summary.html
It contains activity animations like scale up animations. Hope this helps.
也许为时已晚,但我发现支持库包含ActivityOptionsCompat
:https: //developer.android.com/reference/android/support/v4/app/package-summary.html
它包含活动动画,如放大动画。希望这可以帮助。
回答by Inoy
This one have transitions.
这个有过渡。
Hope you'll extract transitions from there.
希望你能从那里提取过渡。
Guide - http://antonioleiva.com/material-design-everywhere/
Code - https://github.com/antoniolg/MaterialEverywhere
指南 - http://antonioleiva.com/material-design-everywhere/
代码 - https://github.com/antoniolg/MaterialEverywhere
回答by matiash
I guess they could be implemented with fragments but I might suspect they would be separate activities. Android L introduces Activity Transitionsas part of the Animation framework. In particular, there transitions can contain shared UI elements, which indicate mappings between "corresponding" views in the caller and called activities. The transition is then included as part of the ActivityOptions
object passed to startActivity()
.
我想它们可以用片段来实现,但我可能怀疑它们是单独的活动。Android L 引入了Activity Transitions作为动画框架的一部分。特别是,过渡可以包含共享 UI 元素,这些元素指示调用者和被调用活动中“相应”视图之间的映射。然后将过渡作为ActivityOptions
传递给的对象的一部分包含在内startActivity()
。
The idea is to achieve the visual effect in those videos (i.e. of particular views changing positions or dimensions as part of an activity transition). The canonical example would be a Gallery app, when transitioning from the grid that shows all images to displaying a particular one.
这个想法是在这些视频中实现视觉效果(即作为活动过渡的一部分改变位置或尺寸的特定视图)。典型的例子是图库应用程序,当从显示所有图像的网格过渡到显示特定图像时。
This couldbe achieved before (please check this answeror this DevBytes video by Chet Haase) but it was rather complex/hacky so it was included as a standard resource in Android L.
这可以在之前实现(请查看这个答案或Chet Haase 的这个 DevBytes 视频),但它相当复杂/hacky,因此它被作为标准资源包含在 Android L 中。
Check the documentation for Activity Transitionsin the L preview documentation, or the ActivitySceneTransitionBasic
included as part of the android-L samples (also remember that you can download the L reference preview from hereto get the documentation for the new methods).
查看L 预览文档中的Activity Transitions文档,或ActivitySceneTransitionBasic
作为 android-L 示例的一部分包含在内(还请记住,您可以从此处下载 L 参考预览以获取新方法的文档)。
回答by manju h
Step 1:Consider that you are moving from one activity to other.So define onclick method for button
第 1 步:考虑您正在从一个活动移动到另一个活动。因此为按钮定义 onclick 方法
button= (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), Animation.class);
startActivity(intent, options.toBundle());
startActivity(intent);
overridePendingTransition (R.anim.right_slide_in, R.anim.right_slide_out);
}
});
Step 2:Now define the animation that you need for the second activity while launching
第 2 步:现在定义启动时第二个活动所需的动画
anim.right_slide_in
anim.right_slide_in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<translate
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="700"
/>
</set>