Animation主要有四大属性,分别是淡入淡出,绕轴旋转,变化大小,位移变化,如图:

这些属性还有一些共同的方法:

下面是一个实例代码:

public class MainActivity extends Activity implements OnClickListener { /** * 定义四个按钮和一张图片 */ private ImageView imageView = null; private Button rotateButton = null; private Button scaleButton = null; private Button alphaButton = null; private Button translateButton = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initView(); } /** * 初始化界面 */ public void initView() { imageView = (ImageView) findViewById(R.id.imageViewId); rotateButton = (Button) findViewById(R.id.rotateButtonId); translateButton = (Button) findViewById(R.id.translateButtonId); scaleButton = (Button) findViewById(R.id.scaleButtonId); alphaButton = (Button) findViewById(R.id.alphaButtonId); rotateButton.setOnClickListener(this); scaleButton.setOnClickListener(this); alphaButton.setOnClickListener(this); translateButton.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub int switchID = v.getId(); switch (switchID) { case R.id.alphaButtonId: { AnimationSet animationSet = new AnimationSet(true);//创建一个AnimationSet对象 AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);//创建一个AlphaAnimation对象 alphaAnimation.setDuration(1000);//设置动画执行的时间(单位:毫秒) animationSet.addAnimation(alphaAnimation);//将AlphaAnimation对象添加到AnimationSet当中 imageView.startAnimation(animationSet);//使用ImageView的startAnimation方法开始执行动画 break; } case R.id.rotateButtonId: { AnimationSet animationSet = new AnimationSet(true); /** * 前两个参数定义旋转的起始和结束的度数,后两个参数定义圆心的位置 */ RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_PARENT, 1f, Animation.RELATIVE_TO_PARENT, 0f); rotateAnimation.setDuration(5000); animationSet.addAnimation(rotateAnimation); imageView.startAnimation(animationSet); break; } case R.id.scaleButtonId: { AnimationSet animationSet = new AnimationSet(true); /** * 围绕一个点伸缩 */ ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 1, 0.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animationSet.addAnimation(scaleAnimation); animationSet.setStartOffset(1000); animationSet.setFillAfter(true); animationSet.setFillBefore(false); animationSet.setDuration(2000); imageView.startAnimation(animationSet); break; } case R.id.translateButtonId: { AnimationSet animationSet = new AnimationSet(true); /** * x和y轴的起始和结束位置 */ TranslateAnimation translateAnimation = new TranslateAnimation ( Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1.0f ); translateAnimation.setDuration(1000); animationSet.addAnimation(translateAnimation); imageView.startAnimation(animationSet); break; } } } }

ok!

更多相关文章

  1. 写在20110721:横竖屏切换
  2. Android(安卓)8.1 添加属性SystemProperties.set可执行权限
  3. Android(安卓)Service之bindService()
  4. android gridview 属性集合
  5. java 自定义注解(翻译)
  6. android 小技巧,不断更新中
  7. RadioButton样式自定义
  8. Handler内存泄露原理及解决方法
  9. LeanCanary——消除Android中的内存泄露

随机推荐

  1. android studio使用快捷键大全
  2. Android的休眠与唤醒 && 实例
  3. android 日常迭代与维护总结二
  4. 快手内推
  5. android之调用webservice 实现图片上传
  6. Android踩坑日记:自定义水平和圆形Progres
  7. Android(安卓)Monkey测试脚本
  8. Android(安卓)应用程序结构介绍
  9. Android常见Exception解决方法
  10. Android中图像变换Matrix的原理、代码验