Go Android 5.0--material Design Details (animated article)

Source: Internet
Author: User

Material Design : Google launched a new design language, it is characterized by the flattening of the object.

Material design contains a lot of content to share with you today Material new animations:

There are several new animations in Android L:

* MIDDOT; Touch Feedback(tactile feedback)

* MIDDOT; Reveal effect(uncovering effect)

* MIDDOT; Activity Transitions(activity conversion effect)

* MIDDOT; Curved motion(curved motion)

* MIDDOT; View state changes (viewstate change)

* MIDDOT; Animate vector drawables(can draw vector animation)

This article first introduces the above 6 kinds of the more commonly used in the first three kinds.

Touch Feedback

Added touch feedback animations to Android 5.0.

One of the most obvious and most representative of these is the Ripple animation, which produces a ripple-like diffusion effect from the point of click When the button is clicked.

Ripple Effect ( Ripple ):

When you use the material theme, the Ripple animation is automatically applied to all the controls, and we can certainly set its properties to adjust to the effect we need.

You can set the background of the ripple with the following code:

android:background= "? Android:attr/selectableitembackground" Ripple has boundary

android:background= "? android:attr/selectableitembackgroundborderless" ripple out of bounds

Use the effect as follows:

B1 is a button with no background

B2 set ? android:attr/selectableitembackground

B3 set ? android:attr/selectableitembackgroundborderless

To set the color:

We can also adjust the animation colors by setting the XML properties so that we can adapt to different topics:

Android:colorcontrolhighlight : Set Ripple Color

android:coloraccent : Set the selected color of a control such as a checkbox

For example, the following is a more matte theme, you need to modify the animation color to match:

Circular Reveal

Circular reveal is a new animated effect of Android L.

How to use:

Application Viewanimationutils.createcircularreveal () Method can be used to create a revealanimator animation viewanimationutils.createcircularreveal source code as follows:

1

2

3

4

public static Animator createcircularreveal (view view,

int CenterX, int centery, float Startradius, float Endradius) {

return new Revealanimator (view, CenterX, CenterY, Startradius, Endradius);

}

The source code is very simple, that is, through the Createcircularreveal method to create a Revealanimator animation object based on 5 parameters. These 5 parameters are:

* Middot;view view of the Operation

* Middot;centerx the center point at which the animation begins X

* Middot;centery the center point at which the animation begins Y

* Middot;startradius Animation Start Radius

* Middot;startradius Animation End Radius

According to the following and code can easily understand the role of these parameters:

code example:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

Final View oval = This.findviewbyid (r.id.oval);

Oval.setonclicklistener (New View.onclicklistener () {

@Override

public void OnClick (View v) {

Animator Animator = Viewanimationutils.createcircularreveal (

Oval

Oval.getwidth ()/2,

Oval.getheight ()/2,

Oval.getwidth (),

0);

Animator.setinterpolator (New Acceleratedecelerateinterpolator ());

Animator.setduration (2000);

Animator.start ();

}

});

Final View rect = This.findviewbyid (r.id.rect);

Rect.setonclicklistener (New View.onclicklistener () {

@Override

public void OnClick (View v) {

Animator Animator = Viewanimationutils.createcircularreveal (

Rect

0,

0,

0,

(float) Math.hypot (Rect.getwidth (), Rect.getheight ()));

Animator.setinterpolator (New Accelerateinterpolator ());

Animator.setduration (2000);

Animator.start ();

}

});

Summarize:

There's no difference between revealanimator and previous animations, and you can also set up listeners and accelerators to implement a variety of effects. These effects are often used in the addition, deletion, state, and size of the view.

Activity Transition

Activity Transition is an animated effect provided in material design. It produces various animation effects by moving and switching elements between different states.

Brief introduction

Activity transition provides two types of transition:

1. Enter (Enter): Enter an activity effect

2. Exit (exit): The effect of quitting an activity

Each of these types is divided into common and shared element transition.

Normal Transition

Explode : move in or out from the center of the scene

Slide : move in or out from the edge of the scene

Fade : Adjust transparency to create a gradient effect

Shared Elements Transition shared element Conversions

Its role is to share two acitivity common elements, under Android 5.0 support the following effects:

changebounds -Change the layout bounds of the target view

changeclipbounds -crop the target view boundary

changetransform -Change the zoom scale and rotation angle of the target view

changeimagetransform -Change the size and scale of the target image

Here is a small demo I wrote, I believe you can see how these several animations work:

Activity Transition Use

Using activity transition is simple and requires only the following two steps:

Step One: set allow transition to be used, and set transition.

XML :

First, if you need to modify the style file to use transition, add the following attribute to the Style.xml that inherits the material theme:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<style name= "MyTheme" parent= "android:Theme.Material" >

<!--allowed to use transitions--

<item name= "Android:windowcontenttransitions" >true</item>

<!--specify entry and exit transitions--

<item name= "Android:windowentertransition" > @transition/explode</item>

<item name= "Android:windowexittransition" > @transition/explode</item>

<!--specify shared element transitions--

<item name= "Android:windowsharedelemententertransition" >

@transition/change_image_transform</item>

<item name= "Android:windowsharedelementexittransition" >

@transition/change_image_transform</item>

</style>

Here's another look at how to define transition animations:

1

2

3

4

5

6

7

<transitionset xmlns:android= "Http://schemas.android.com/apk/res/android" >

<explode/>

<changeBounds/>

<changeTransform/>

<changeClipBounds/>

<changeImageTransform/>

</transitionSet>

Transition inside the elements using the same method and the previous animationset, how to use people can refer to the official documents.

Code:

You can also complete the settings for transition in your code:

1

2

3

4

5

Allow use of transitions

GetWindow (). Requestfeature (window.feature_content_transitions);

Set an exit transition

GetWindow (). Setexittransition (New Explode ());

You can always set the transition effect in your code in the following ways:

window.setentertransition () : The entry effect of ordinary transition

window.setexittransition () : exit effect of normal transition

window.setsharedelemententertransition () : The entry effect of the shared element transition

window.setsharedelementexittransition () : The exit effect of the shared element transition

Step Two: start activity.

When you have set the Allow to use transition and set the transition animation, you can go through the activityoptions.makescenetransitionanimation () Method starts a new activity to activate the transition:

enable the normal Transition :

1

2

StartActivity (Intent,

Activityoptions.makescenetransitionanimation (This). Tobundle ());

Enable shared elements Transition :

Starting shared element transition is slightly different from normal transition, and in all activity that needs to share views, use the Android:transitionname property to assign a common name to the element that needs to be shared.

1

2

3

4

5

6

Intent Intent = new Intent (this, activity2.class);

Shareview: Views that need to be shared

"ShareName": Set Android:transitionname= "ShareName"

Activityoptions options = activityoptions

. makescenetransitionanimation (This, Shareview, "shareName");

StartActivity (Intent, Options.tobundle ());</span>

If more than one view needs to be shared, multiple matching pairs are created through the Pair.create () method and then passed in to Activityoptions.makescenetransitionanimation.

The code is as follows:

1

2

3

Activityoptions options = Activityoptions.makescenetransitionanimation (This,

Pair.create (View1, "agreedName1"),

Pair.create (View2, "agreedName2"));

If you do not want to use transition, you can set the options bundle to null. Call the Activity.finishaftertransition () method when you need to end the current activity and roll back the animation.

Compatibility:

Several of the new animated APIs described above are only allowed for use in Android L:

* MIDDOT; Activity transitions

* MIDDOT; Touch Feedback

* MIDDOT; Reveal Animations

So in order to be compatible with earlier versions, you need to check the system version before calling these APIs.

Go Android 5.0--material Design Details (animated article)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.