目标是在Onclick事件中为用户点击ImageButton提供一些反馈。我知道可以根据按钮的状态更改图像,但是如果在运行时加载了太多不同的图像,则会更加困难。
我这样做了,但不是那么漂亮
public void homeButtonClick(View view) {
ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.9f);
ObjectAnimator scaleDownY = ObjectAnimator.ofFloat(view, "scaleY", 1.0f, 0.9f);
ObjectAnimator scaleUpX = ObjectAnimator.ofFloat(view, "scaleX", 0.9f, 1f);
ObjectAnimator scaleUpY = ObjectAnimator.ofFloat(view, "scaleY", 0.9f, 1.0f);
AnimatorSet scaling = new AnimatorSet();
scaling.play(scaleUpX).with(scaleUpY).after(scaleDownX).with(scaleDownY);
scaling.setDuration(100);
scaling.start();
scaling.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
Intent intent = new Intent(MainActivity.this, ContentActivity.class);
startActivity(intent);
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
完成动画后,它会调用一个新的Activity