Android 图片动画,点击缩放回弹

private void animationScale(View v){
    ObjectAnimator animatorX  = ObjectAnimator.ofFloat(v,"ScaleX", 1.0F, 0.8F, 1.2F, 1.0F);
    ObjectAnimator animatorY = ObjectAnimator.ofFloat(v,"ScaleY", 1.0F, 0.8F, 1.2F, 1.0F);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(animatorX, animatorY);
    animatorSet.setDuration(80);
    animatorSet.start();
}
class tabOntouchListener implements View.OnTouchListener{
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()){
            case MotionEvent.ACTION_UP:
                animationScale(v);
                break;
        }
        return false;
    }
}

mTabHost.getTabWidget().getChildAt(0).setOnTouchListener(new tabOntouchListener());
这样的效果只在手机“开发者选项”中设置为开启动画时才有效果;如果希望在关闭动画的时候也希望有效果我是下面这样写的
 static  float scalex[]={1.0F, 0.8F, 1.2F, 1.0F};
    private static void animationScale(final View v,final int time,final int index){
        
        final AnimationSet animationSet = new AnimationSet(true);
        ScaleAnimation scaleAnimation = new ScaleAnimation(scalex[index],scalex[index+1],scalex[index],scalex[index+1], Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        //3秒完成动画
        scaleAnimation.setDuration(time);
        animationSet.addAnimation(scaleAnimation);
        //启动动画
        v.startAnimation(animationSet);
        animationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if(index < scalex.length-2){
                    animationScale(v,time,index+1);
                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

    }
--------------------- 
作者:muxsero 
来源:CSDN 
原文:https://blog.csdn.net/a243920187/article/details/52620329 
版权声明:本文为博主原创文章,转载请附上博文链接!

https://blog.csdn.net/a243920187/article/details/52620329
https://blog.csdn.net/qq_22770457/article/details/78630695 Android——腾讯QQ的Tab按钮动画效果完美实现

你可能感兴趣的:(android)