1.定义按钮和翻转前后的两个图片
TextView textView1=findViewById(R.id.tv2);
// 假设你的两张图片分别为image1和image2
final ImageView image1 = findViewById(R.id.imageView100);
final ImageView image2 = findViewById(R.id.imageView101);
2.把翻转后的图片隐藏
// 初始时,让image2隐藏
image2.setVisibility(View.GONE);
3.对按钮添加点击事件
textView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 创建一个翻转动画
ObjectAnimator animator1 = ObjectAnimator.ofFloat(image1, "rotationY", 0.0f, 90.0f);
animator1.setDuration(1000);
animator1.setInterpolator(new DecelerateInterpolator());
final ObjectAnimator animator2 = ObjectAnimator.ofFloat(image2, "rotationY", -90.0f, 0.0f);
animator2.setDuration(1000);
animator2.setInterpolator(new AccelerateInterpolator());
// 设置动画监听
animator1.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
// 动画结束时,隐藏image1,显示image2,然后开始image2的动画
image1.setVisibility(View.GONE);
image2.setVisibility(View.VISIBLE);
animator2.start();
}
});
// 开始动画
animator1.start();
}
});