属性组合动画
程序员文章站
2022-03-02 19:44:13
...
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
private int in = 5;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (in > 0) {
in--;
handler.sendEmptyMessageDelayed(0,1000);
} else {
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
handler.sendEmptyMessageDelayed(0,1000);
}
/**
* 初始化控件
*/
private void initView() {
imageView = (ImageView) findViewById(R.id.imageView);
// 旋转
PropertyValuesHolder propertyValuesHolder1 = PropertyValuesHolder.ofFloat("rotation", 0f, 360f);
// x轴方向平移
// PropertyValuesHolder propertyValuesHolder2 = PropertyValuesHolder.ofFloat("translationX", 0f, 200f);
// y轴方向平移 "alpha", 0f, 1f
PropertyValuesHolder propertyValuesHolder3 = PropertyValuesHolder.ofFloat("translationY", 0f, 200f);
PropertyValuesHolder propertyValuesHolder4 = PropertyValuesHolder.ofFloat("scaleY", 5f, 1f);
PropertyValuesHolder propertyValuesHolder5 = PropertyValuesHolder.ofFloat("alpha", 0f, 1f);
ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(imageView, propertyValuesHolder1, propertyValuesHolder3, propertyValuesHolder4, propertyValuesHolder5);
// 设置间隔时间
objectAnimator.setDuration(5000);
// 开始动画
objectAnimator.start();
Toast.makeText(MainActivity.this, "跳转", Toast.LENGTH_SHORT).show();
}
}
上一篇: Android 动画知识总结