安卓材料设计 - 材料动画

4
我想要制作一个包含项目列表的应用程序。当用户点击一个项目时,我希望使用这里描述的材料运动效果来进行动画处理。
Android库本身是否包含它?如果不包含,那么有没有第三方库可供此动画使用?
您可以在此视频中查看该动画:视频链接

1
请参考 https://developer.android.com/training/material/animations.html 中的 使用共享元素启动活动 部分。 - Virat18
1个回答

6

你可以使用共享元素转换

https://github.com/codepath/android_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

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
}

输出

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接