Android 仿QQ底部导航图片点击 旋转 缩放动画

1.俩张图

Android 仿QQ底部导航图片点击 旋转 缩放动画_第1张图片

这样



    

 


然后这样

public class MainActivity extends AppCompatActivity {

    private ImageView image;
    private ImageView image2;
    private int lastindex;  //上一条
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        final Animation animationRotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
        animationRotate.setInterpolator(new LinearInterpolator());//设置为线性旋转

        image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                image.startAnimation(animationRotate);
                animationRotate.setFillAfter(!animationRotate.getFillAfter());
            }
        });

        final AnimatorSet animatorSetsuofang = getAnimatorSet(image2);

        image2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                animatorSetsuofang.start();
                animatorSetsuofang.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        image2.setImageResource(R.drawable.appmanager);


                        //一个思路 可以 写个变量  int x  和当前一样  就return
                        // 在点击新的图片是 让之前的 还原 重新setImage

                    }
                });
            }
        });
    }
    
    private AnimatorSet getAnimatorSet(ImageView imageView) {
        final AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 1f,0, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 1f,0, 1f);
        animatorSetsuofang.setDuration(1000);
        animatorSetsuofang.setInterpolator(new DecelerateInterpolator());
        animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始
        return animatorSetsuofang;
    }

    private void initView() {
        image = (ImageView) findViewById(R.id.image);
        image2 = (ImageView) findViewById(R.id.image2);
    }
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Android 仿QQ底部导航图片点击 旋转 缩放动画)