ObjectAnimator property animation application demo, objectanimatordemo

Source: Internet
Author: User

ObjectAnimator property animation application demo, objectanimatordemo

Thanks to MOOC-eclipse_xu

Layout file: activity_main.xml

1 <FrameLayout xmlns: android = "http://schemas.android.com/apk/res/android" 2 xmlns: tools = "http://schemas.android.com/tools" 3 android: layout_width = "match_parent" 4 android: layout_height = "match_parent" 5 tools: context = "com. example. animationapp. mainActivity "> 6 7 <ImageView 8 android: id =" @ + id/im0 "9 android: layout_width =" wrap_content "10 android: layout_height =" wrap_content "11 android: paddingLeft = "3dp" 12 android: paddingTop = "3dp" 13 android: src = "@ drawable/B"/> 14 15 <ImageView16 android: id = "@ + id/im1" 17 android: layout_width = "wrap_content" 18 android: layout_height = "wrap_content" 19 android: paddingLeft = "3dp" 20 android: paddingTop = "3dp" 21 android: src = "@ drawable/c"/> 22 23 <ImageView24 android: id = "@ + id/im2" 25 android: layout_width = "wrap_content" 26 android: layout_height = "wrap_content" 27 android: paddingLeft = "3dp" 28 android: paddingTop = "3dp" 29 android: src = "@ drawable/d"/> 30 31 <ImageView32 android: id = "@ + id/im3" 33 android: layout_width = "wrap_content" 34 android: layout_height = "wrap_content" 35 android: paddingLeft = "3dp" 36 android: paddingTop = "3dp" 37 android: src = "@ drawable/e"/> 38 39 <ImageView40 android: id = "@ + id/im4" 41 android: layout_width = "wrap_content" 42 android: layout_height = "wrap_content" 43 android: paddingLeft = "3dp" 44 android: paddingTop = "3dp" 45 android: src = "@ drawable/f"/> 46 47 <ImageView48 android: id = "@ + id/im5" 49 android: layout_width = "wrap_content" 50 android: layout_height = "wrap_content" 51 android: paddingLeft = "3dp" 52 android: paddingTop = "3dp" 53 android: src = "@ drawable/g"/> 54 55 <ImageView56 android: id = "@ + id/im6" 57 android: layout_width = "wrap_content" 58 android: layout_height = "wrap_content" 59 android: paddingLeft = "3dp" 60 android: paddingTop = "3dp" 61 android: src = "@ drawable/h"/> 62 63 <ImageView64 android: id = "@ + id/im7" 65 android: layout_width = "wrap_content" 66 android: layout_height = "wrap_content" 67 android: src = "@ drawable/a"/> 68 69 </FrameLayout>View Code

Image Resources

MainActivity. java

1 package com. example. animationapp; 2 3 import java. util. arrayList; 4 import java. util. list; 5 6 import android. support. v7.app. actionBarActivity; 7 import android. animation. objectAnimator; 8 import android. OS. bundle; 9 import android. view. menu; 10 import android. view. menuItem; 11 import android. view. view; 12 import android. view. view. onClickListener; 13 import android. view. animation. bounceInterpolator; 14 import android. widget. imageView; 15 import android. widget. toast; 16 17 public class MainActivity extends ActionBarActivity implements OnClickListener {18 19 private int [] res = {R. id. im0, R. id. im1, R. id. im2, 20 R. id. im3, R. id. im4, R. id. im5, R. id. im6, R. id. im7}; 21 22 private List <ImageView> list = new ArrayList <ImageView> (); 23 24 private boolean flag = true; 25 26 @ Override27 protected void onCreate (Bundle savedInstanceState) {28 super. onCreate (savedInstanceState); 29 setContentView (R. layout. activity_main); 30 31 initView (); 32} 33 34 private void initView () {35 36 for (int I = 0; I <res. length; I ++) {37 ImageView im = (ImageView) findViewById (res [I]); 38 im. setOnClickListener (this); 39 list. add (im); 40} 41} 42 43 @ Override44 public void onClick (View v) {45 switch (v. getId () {46 // The Last layout of im7, superimposed on the top 47 case R. id. im7: {48 49 if (flag) {50 startAnimation (); 51 flag = false; 52} else {53 closeAnimation (); 54 flag = true; 55} 56 break; 57} 58 59 default: 60 Toast. makeText (MainActivity. this, v. getId () + "OK", Toast. LENGTH_SHORT ). show (); 61 break; 62} 63} 64 65 private void closeAnimation () {66 for (int I = 0; I <res. length-1; I ++) {67 ObjectAnimator oa = ObjectAnimator. ofFloat (list. get (I), 68 "translationY", I * 200F, 0F); 69 oa. setDuration (100); 70 // oa. setStartDelay (50 * I); 71 oa. start (); 72} 73} 74 75 private void startAnimation () {76 // only seven other icons need to be displayed here, im7 does not move 77 for (int I = 0; I <res. length-1; I ++) {78 // attribute animation operation class 79 ObjectAnimator oa = ObjectAnimator. ofFloat (list. get (I), 80 "translationY", 0F, I * 200F); 81 oa. setDuration (200); 82 // oa. setInterpolator (new BounceInterpolator (); 83 // oa. setstartdelay( 200 * I); 84 oa. start (); 85} 86} 87 88}View Code

 

Related 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.