1. 程式人生 > >點選動畫 波紋效果 主要用來做引導動畫

點選動畫 波紋效果 主要用來做引導動畫

public class Animation5 extends Activity {

    private ImageView animationiv1;
    private ImageView animationiv2;
    private ImageView animationiv3;
    private boolean isDouble true;
@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
setContentView(R.layout.animation_5
);
animationiv1 = (ImageView) findViewById(R.id.animation_iv_1);
animationiv2 = (ImageView) findViewById(R.id.animation_iv_2);
animationiv3 = (ImageView) findViewById(R.id.animation_iv_3);
//這個是 控制元件實現
final ClickAnimationView animation_cav = (ClickAnimationView) findViewById(R.id.animation_cav);
animation_cav.setOnCallBackListener(new 
OnCallBackListener() {
            @Override
public void onCallBack(String resultObject resultObj) {
                Log.i("Animation5","點選");
}
        });
        this.findViewById(R.id.animation_bt_double).setOnClickListener(new View.OnClickListener() {
            @Override
public void onClick
(View v) {
                isDouble true;
initDoubleAnimation();
animation_cav.setClickSingleOrDouble(false);
}
        });
        this.findViewById(R.id.animation_bt_single).setOnClickListener(new View.OnClickListener() {
            @Override
public void onClick(View v) {
                isDouble false;
initSingleAnimation();
animation_cav.setClickSingleOrDouble(true);
}
        });
initSingleAnimation();
}

    /**
     * 佈局雙擊圓圈擴散動畫
     */
private void initDoubleAnimation() {

        if(!isDouble){
            return;
}

        animationiv3.setVisibility(View.VISIBLE);
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation sacleAnimation = new ScaleAnimation(1.0f1.05f1.0f1.05f,
Animation.RELATIVE_TO_SELF0.5fAnimation.RELATIVE_TO_SELF0.5f);
sacleAnimation.setDuration(200);
sacleAnimation.setInterpolator(new AccelerateInterpolator());
sacleAnimation.setFillAfter(true);
sacleAnimation.setRepeatCount(1);
ScaleAnimation sacleAnimation3 = new ScaleAnimation(1.05f1.0f1.05f1.0f,
Animation.RELATIVE_TO_SELF0.5fAnimation.RELATIVE_TO_SELF0.5f);
sacleAnimation3.setDuration(200);
sacleAnimation3.setFillAfter(true);
sacleAnimation3.setRepeatCount(1);
sacleAnimation3.setInterpolator(new AccelerateInterpolator());
sacleAnimation3.setStartOffset(200);
animationSet.addAnimation(sacleAnimation);
animationSet.addAnimation(sacleAnimation3);
animationiv1.startAnimation(animationSet);
AnimationSet animationSet1 = new AnimationSet(true);
ScaleAnimation sacleAnimation1 = new ScaleAnimation(1.1f3.0f1.1f3.0f,
Animation.RELATIVE_TO_SELF0.5fAnimation.RELATIVE_TO_SELF0.5f);
sacleAnimation1.setDuration(500);
AlphaAnimation alphaAnimation1 = new AlphaAnimation(1.0f0);
alphaAnimation1.setDuration(500);//設定動畫持續時間
animationSet1.addAnimation(sacleAnimation1);
animationSet1.addAnimation(alphaAnimation1);
animationSet1.setInterpolator(new DecelerateInterpolator());
animationSet1.setStartOffset(100);
animationSet1.setFillAfter(true);
animationiv2.startAnimation(animationSet1);
AnimationSet animationSet2 = new AnimationSet(true);
ScaleAnimation sacleAnimation2 = new ScaleAnimation(1.1f3.0f1.1f3.0f,
Animation.RELATIVE_TO_SELF0.5fAnimation.RELATIVE_TO_SELF0.5f);
sacleAnimation2.setDuration(500);
AlphaAnimation alphaAnimation2 = new AlphaAnimation(1.0f0);
alphaAnimation2.setDuration(500);//設定動畫持續時間
animationSet2.addAnimation(sacleAnimation2);
animationSet2.addAnimation(alphaAnimation2);
animationSet2.setStartOffset(400);
animationSet2.setInterpolator(new DecelerateInterpolator());
animationSet2.setFillAfter(true);
animationiv3.startAnimation(animationSet2);
animationSet2.setAnimationListener(new Animation.AnimationListener() {
            @Override
public void onAnimationStart(Animation animation) {

            }

            @Override
public void onAnimationEnd(Animation animation) {
                new Handler().postDelayed(new Runnable() {
                    @Override
public void run() {
                        initDoubleAnimation();
}
                }500);
}

            @Override
public void onAnimationRepeat(Animation animation) {

            }
        });
}

    /**
     * 佈局單擊動畫
     */
private void initSingleAnimation() {

        if(isDouble){
            return;
}

        animationiv3.setVisibility(View.GONE);
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation sacleAnimationBig = new ScaleAnimation(1.0f1.05f1.0f1.05f,
Animation.RELATIVE_TO_SELF0.5fAnimation.RELATIVE_TO_SELF0.5f);
sacleAnimationBig.setDuration(200);
sacleAnimationBig.setInterpolator(new AccelerateInterpolator());
sacleAnimationBig.setFillAfter(true);
ScaleAnimation sacleAnimationSmall = new ScaleAnimation(1.05f1.0f1.05f1.0f,
Animation.RELATIVE_TO_SELF0.5fAnimation.RELATIVE_TO_SELF0.5f);
sacleAnimationSmall.setDuration(200);
sacleAnimationSmall.setFillAfter(true);
sacleAnimationSmall.setInterpolator(new AccelerateInterpolator());
sacleAnimationSmall.setStartOffset(200);
animationSet.addAnimation(sacleAnimationBig);
animationSet.addAnimation(sacleAnimationSmall);
animationiv1.startAnimation(animationSet);
AnimationSet animationSetChild = new AnimationSet(true);
ScaleAnimation sacleAnimation1 = new ScaleAnimation(1.1f4.0f1.1f4.0f,
Animation.RELATIVE_TO_SELF0.5fAnimation.RELATIVE_TO_SELF0.5f);
sacleAnimation1.setDuration(500);
AlphaAnimation alphaAnimation1 = new AlphaAnimation(1.0f0);
alphaAnimation1.setDuration(500);//設定動畫持續時間
animationSetChild.addAnimation(sacleAnimation1);
animationSetChild.addAnimation(alphaAnimation1);
animationSetChild.setInterpolator(new DecelerateInterpolator());
animationSetChild.setStartOffset(100);
animationSetChild.setFillAfter(true);
animationiv2.startAnimation(animationSetChild);
animationSetChild.setAnimationListener(new Animation.AnimationListener() {
            @Override
public void onAnimationStart(Animation animation) {

            }

            @Override
public void onAnimationEnd(Animation animation) {
                new Handler().postDelayed(new Runnable() {
                    @Override
public void run() {
                        initSingleAnimation();
}
                }500);
}

            @Override
public void onAnimationRepeat(Animation animation) {

            }
        });
}


}