标签:
动画(4)自定义动画
使用监听事件对animation 进行状态的变化
large.xml
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXScale="0.2" android:fromYScale="0.2" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.0" android:toYScale="1.0" > </scale>
small.xml
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:toXScale="0.2" android:toYScale="0.2" > </scale>
public class MainActivity extends Activity implements AnimationListener{ Animation big; Animation small; ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView)findViewById(R.id.imageView1); big = AnimationUtils.loadAnimation(this, R.anim.large); small = AnimationUtils.loadAnimation(this, R.anim.small);
//动画的事件监听 big.setAnimationListener(this); small.setAnimationListener(this); } public void click(View v){ switch (v.getId()) { case R.id.button1: iv.startAnimation(small); break; } }
//三种状态,开始,,结束,, 重复
//一般在结束事件后,进行另一事件的开始 public void onAnimationStart(Animation animation) { } public void onAnimationEnd(Animation animation) { if(animation.hashCode() ==big.hashCode()){ iv.startAnimation(small); }else if(animation.hashCode() == small.hashCode()){ iv.startAnimation(big); } } public void onAnimationRepeat(Animation animation) { } }
动画(4)自定义动画
标签:
原文地址:http://www.cnblogs.com/chengbao/p/5628781.html