ObjectAnimator (used for testing and used for testing in Android animation operations)

Source: Internet
Author: User

ObjectAnimator (used for testing and used for testing in Android animation operations)

Let's just look at the code.

It should be noted that ObjectAnimator. ofFloat (xiaoming, "age", 0f, 100f) is passed in the float value. Therefore, in the test, the age must be of the float type and the setAge method must be used, otherwise, the value cannot be passed.First look at the layout File

      
      
   
Main program code
package com.test.testone;import android.support.v7.app.ActionBarActivity;import android.util.Log;import android.animation.Animator;import android.animation.Animator.AnimatorListener;import android.annotation.TargetApi;import android.app.Activity;import android.animation.ObjectAnimator;import android.os.Build;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.view.animation.Animation;import android.widget.Button;import android.widget.TextView;@TargetApi(Build.VERSION_CODES.HONEYCOMB)public class MainActivity extends Activity {    private static final String TAG=AA;    private Student xiaoming;    private Button mButton;    private TextView mTextView;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);         mButton=(Button) findViewById(R.id.button);         mTextView=(TextView) findViewById(R.id.text_view);         mButton.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View v) {                 xiaoming=new Student();                ObjectAnimator anim=  ObjectAnimator.ofFloat(xiaoming, age, 0f,100f).setDuration(1000);                  anim.addListener(new AnimatorListener()                      {                        @Override                        public void onAnimationStart(Animator animation) {                             Log.d(TAG, onAnimationStart);                          }                        @Override                        public void onAnimationEnd(Animator animation) {                             Log.d(lalala, onAnimationEnd);                               Log.d(lalala, xiaoming.getAge()+);                             mTextView.setText( xiaoming.getAge()+);                        }                        @Override                        public void onAnimationCancel(Animator animation) {                              Log.d(TAG, onAnimationCancel);                          }                        @Override                        public void onAnimationRepeat(Animator animation) {                             Log.d(TAG, onAnimationRepeat);                          }                      });                      anim.start();              }        });    }}
Auxiliary student Class
package com.test.testone;public class Student {    private float age;    public float getAge() {        return age;    }    public void setAge(float age) {        this.age = age;    }}

We can see that the value of age is changed from the default value to the input value of 100. This shows the multi-purpose of ObjectAnimator. It can be used in both animation effects and more scenarios.

 

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.