Summary of the First practice of Android property animation and the first practice of android

Source: Internet
Author: User

Summary of the First practice of Android property animation and the first practice of android

After these two days of learning about ObjectAnimator property animation, I have a certain understanding of the property animation provided by Android. Now I will summarize the effect of opening a similar slice.

:

Next let's use the property animation effect we just learned to achieve the above effect. First, we need to prepare eight small icons and put them in the drawable file under the res directory, the following is the layout file. The layout file is very simple. It is to introduce the eight small icons into the interface using ImageView. Note that the icons used as the switch are placed at the bottom, the specific implementation is as follows:

/*** Example of attribute animation synthesis * Created by Administrator on. */public class ThreeActivity extends Activity implements View. onClickListener {private int [] image = {R. id. imageA, R. id. imageB, R. id. imageC, R. id. imageD, R. id. imageE, R. id. imageF, R. id. imageG, R. id. imageH}; private String [] str = {"Switch", "camera", "Music", "Address", "moon", "personal information", "positioning ", "SMS"}; private List <ImageView> list = new ArrayList <ImageView> (); private Boolean flag = true; // open or close the icon control @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_three); init ();} public void init () {for (int I = 0; I <image. length; I ++) {ImageView imageView = (ImageView) findViewById (image [I]); imageView. setOnClickListener (this); list. add (imageView) ;}@ Override public void onClick (View view) {switch (view. getId () {case R. id. imageA: if (flag) {startanim (); // open} else {closeanim (); // collapse} break; case R. id. imageB: Toast. makeText (this, str [1], Toast. LENGTH_SHORT ). show (); break; case R. id. imageC: Toast. makeText (this, str [2], Toast. LENGTH_SHORT ). show (); break; case R. id. imageD: Toast. makeText (this, str [3], Toast. LENGTH_SHORT ). show (); break; case R. id. imageE: Toast. makeText (this, str [4], Toast. LENGTH_SHORT ). show (); break; case R. id. imageF: Toast. makeText (this, str [5], Toast. LENGTH_SHORT ). show (); break; case R. id. imageG: Toast. makeText (this, str [6], Toast. LENGTH_SHORT ). show (); break; case R. id. imageH: Toast. makeText (this, str [7], Toast. LENGTH_SHORT ). show (); break; default: break ;}}
// Open the hidden icon public void startanim () {for (int I = list. size ()-1, j = 0; I> = 0; I --, j ++) {ObjectAnimator animator = ObjectAnimator. ofFloat (list. get (I), "translationY", 0F, I * 80F); animator. setDuration (500); // duration animator. setInterpolator (new BounceInterpolator (); // The animation effect. setStartDelay (j * 100); // The interval is animator. start ();} flag = false ;}
// Close the open public void closeanim () {for (int I = 0; I <list. size (); I ++) {ObjectAnimator animator = ObjectAnimator. ofFloat (list. get (I), "translationY", I * 80F, 0F); animator. setDuration (500); animator. setStartDelay (I * 100); animator. start () ;}flag = true ;}}

For the hard-to-understand part of the code, I have commented on it. I believe you can understand it at a glance. Finally, we will provide you with a post-Internship effect:

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.