Android 心跳呼吸动画

废话少说,看东西

 

一个很简单的心跳呼吸的动画,几行代码搞定;

代码:

    private ImageView ivHart;                //图片
    AlphaAnimation alphaAnimation = null;    //透明度动画

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_anim);

        ivHart = (ImageView) findViewById(R.id.ivHart);
        shadeAnim(ivHart);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (alphaAnimation != null) {
            alphaAnimation.start();
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        if (alphaAnimation != null) {
            alphaAnimation.cancel();
        }
    }

    /**
     * 渐变动画
     *
     * @param view 执行该动画的view对象
     */
    private void shadeAnim(View view) {
        alphaAnimation = new AlphaAnimation(0.1f, 1.0f);
        alphaAnimation.setDuration(1000);
        alphaAnimation.setRepeatCount(-1);
        alphaAnimation.setRepeatMode(Animation.REVERSE);
        alphaAnimation.start();
        view.setAnimation(alphaAnimation);
    }     

 

posted @ 2018-04-10 18:03  geaosu  阅读(998)  评论(0编辑  收藏  举报