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); }
geaosu