Make animations no longer stiff: Facebook rebound Android Animation library Introduction

Source: Internet
Author: User

Introduction

Official Site:http://facebook.github.io/rebound
Github:https://github.com/facebook/rebound
Rebound is a library of elastic animations from Facebook that makes animations look natural, like real-world physical motion, with powerful effects and parameters used by Facebook's origami.
There is a simple JS version of the official website to do the demo, if it is said Evernote, LinkedIn, flow and other applications are also using this animation library, will it appear more powerful?

Specific effect, you can look at the QQ space Android standalone version of the client, the drawer open icon effect, and the bottom plus point opened after the icon effect, I was in the time to do.

Usage
1
2
3
4
5
6
7
8
9
10
 spring Spring = Mspringsystem 
Createspring ()
Span class= "line" > Setspringconfig (springconfig.fromorigamitensionandfriction (86, 7)
AddListener (new simplespringlistener () {
@Override
public void onspringupdate ( Spring Spring) {
float value = (float) Spring.getcurrentvalue ();
Viewhelper.settranslationx (view, value);
/span>

The short code above gives a view a natural, left-to-right entry to the rebound effect.

Similarly,

1
2
3
4
5
6
7
8
9
10
11
12
Spring Spring = Mspringsystem
. Createspring ()
. Setspringconfig (Springconfig.fromorigamitensionandfriction (, 7))
. AddListener (new Simplespringlistener () {
@Override
Public void onspringupdate(Spring spring) {
Float value = (float) spring.getcurrentvalue ();
float scale = 1f-value;
Viewhelper.setscalex (Mitemiconviewlist.get (index), scale);
Viewhelper.setscaley (Mitemiconviewlist.get (index), scale);
}
});

You can add a view to a small size and then a little rebound effect.

What if you want to do a lot of view chain animations? The rebound also provides the Springchain interface.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
for (int i =0; i < Viewcount; i++) {
Final View view =New View (context);
View.setlayoutparams (
New Tablelayout.layoutparams (
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
1f));
Mspringchain.addspring (New Simplespringlistener () {
@Override
PublicvoidOnspringupdate(Spring Spring) {
Float value = (float) spring.getcurrentvalue ();
View.settranslationx (value);
}
});
int color = (Integer) evaluator.evaluate ((float) I/(float) Viewcount, StartColor, EndColor);
View.setbackgroundcolor (color);
View.setontouchlistener (New Ontouchlistener () {
@Override
PublicBooleanOnTouch(View V, motionevent event) {
Return Handlerowtouch (V, event);
}
});
Mviews.add (view);
Rootview.addview (view);
}

Getviewtreeobserver (). Addongloballayoutlistener (New Viewtreeobserver.ongloballayoutlistener () {
@Override
PublicvoidOngloballayout() {
Getviewtreeobserver (). Removeongloballayoutlistener (this);
List<spring> springs = mspringchain.getallsprings ();
for (int i = 0; i < springs.size (); i++) {
Springs.get ( i). Setcurrentvalue (-mviews.get (i). GetWidth ());
postdelayed (new Runnable () {
@Override
void run () {
Mspringchain
0)
0);
500);
/span>

A view and view of the traction displacement animation effect was made.

Make animations no longer stiff: Facebook rebound Android Animation library Introduction

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.