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.