《布局》
《MainActivity》
public class MainActivity extends AppCompatActivity {
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(text, "alpha", 1, 0.8f, 0.6f, 0.2f, 0.2f, 0.5f, 1);
objectAnimator.setDuration(6000);
objectAnimator.start();
}
});
text = (TextView)findViewById(R.id.text);
}
}
====================
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_alpha://实现透明度
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mText, “alpha”, 1, 0.8f, 0.6f, 0.2f, 0, 0.2f, 0.5f, 1);
objectAnimator.setDuration(6000);
objectAnimator.start();
break;
case R.id.btn_translation://平移
//translationY Y轴平移 translationX X轴平移
ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(mText, “translationY”, 0, 100, 300, 500, 300, 0);
objectAnimator1.setDuration(2000);
objectAnimator1.setRepeatCount(10);
objectAnimator1.start();
break;
case R.id.btn_rotation://旋转
ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(mText, “rotation”, 0, 90, 270);
objectAnimator2.setDuration(3000);
objectAnimator2.start();
break;
case R.id.btn_scale://缩放
ObjectAnimator objectAnimator3 = ObjectAnimator.ofFloat(mText, “scaleY”, 1, 2, 3, 2, 1, 0.5f, 0.1f);
objectAnimator3.setDuration(3000);
objectAnimator3.start();
break;
case R.id.btn_color://改变颜色
ObjectAnimator objectAnimator4 = ObjectAnimator.ofInt(mText, “backgroundColor”, Color.RED, Color.YELLOW, Color.BLACK, Color.BLUE);
objectAnimator4.setDuration(3000);
objectAnimator4.start();
break;