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按鈕動畫效果完美實現

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章