Android Material design transitions

北战南征 提交于 2019-12-31 08:11:22

问题


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:

  1. http://material-design.storage.googleapis.com/videos/animations-meaningfultransitions-hierarchical_transitions_topLevel_large_xhdpi.webm
  2. 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?

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)

In other words what the layout (+Activities, fragments) should be if I want to replicate this?


回答1:


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.




回答2:


This one have transitions.

Hope you'll extract transitions from there.

Guide - http://antonioleiva.com/material-design-everywhere/
Code - https://github.com/antoniolg/MaterialEverywhere




回答3:


I guess they could be implemented with fragments but I might suspect they would be separate activities. Android L introduces Activity Transitions as 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().

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 could be achieved before (please check this answer or this DevBytes video by Chet Haase) but it was rather complex/hacky so it was included as a standard resource in Android L.

Check the documentation for Activity Transitions in 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 here to get the documentation for the new methods).




回答4:


Step 1:Consider that you are moving from one activity to other.So define onclick method for button

   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

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>


来源:https://stackoverflow.com/questions/24996723/android-material-design-transitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!