首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android材料设计-材料运动

Android材料设计-材料运动
EN

Stack Overflow用户
提问于 2017-05-08 08:59:41
回答 1查看 2.5K关注 0票数 4

我想做一个应用程序,其中包含项目列表。当用户单击一个项目时,我想用这里描述的物质运动效果来动画它。

android库是否以本地方式包含它?如果没有,是否有这个动画的3.派对库?

你可以在这个视频中看到动画:视频链路

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-08 09:10:05

您可以使用共享元素转换。

guides/wiki/Shared-Element-Activity-Transition

https://github.com/googlesamples/android-ActivitySceneTransitionBasic

https://github.com/toddway/MaterialTransitions

https://github.com/afollestad/shared-element-transition-samples

代码语言:javascript
复制
FirstFragment fragmentOne = ...;
SecondFragment fragmentTwo = ...;
// Check that the device is running lollipop
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    // Inflate transitions to apply
    Transition changeTransform = TransitionInflater.from(this).
          inflateTransition(R.transition.change_image_transform);
    Transition explodeTransform = TransitionInflater.from(this).
          inflateTransition(android.R.transition.explode);

    // Setup exit transition on first fragment
    fragmentOne.setSharedElementReturnTransition(changeTransform);
    fragmentOne.setExitTransition(explodeTransform);

    // Setup enter transition on second fragment
    fragmentTwo.setSharedElementEnterTransition(changeTransform);
    fragmentTwo.setEnterTransition(explodeTransform);

    // Find the shared element (in Fragment A)
    ImageView ivProfile = (ImageView) findViewById(R.id.ivProfile);

    // Add second fragment by replacing first 
    FragmentTransaction ft = getFragmentManager().beginTransaction()
            .replace(R.id.container, fragmentTwo)
            .addToBackStack("transaction")
            .addSharedElement(ivProfile, "profile");
    // Apply the transaction
    ft.commit();
}
else {
    // Code to run on older devices
}

输出

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43843594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档