博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
安卓动画相关 学习笔记
阅读量:7098 次
发布时间:2019-06-28

本文共 2841 字,大约阅读时间需要 9 分钟。

hot3.png

1.帧动画

把连续图片放入 drawable 目录 以及在该目录创建创建一个xml 文件

程序片段

protected void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		setContentView(R.layout.activity_main);		iv = (ImageView) findViewById(R.id.iv);		iv.setBackgroundResource(R.drawable.gril_list);		an = (AnimationDrawable) iv.getBackground();	}		public void play(View view) {		an.start();	}

##2. 程序创建动画

//平移	public void playTranslate(View view)	{		TranslateAnimation ta = new TranslateAnimation(				Animation.RELATIVE_TO_PARENT, 0.0f, 				Animation.RELATIVE_TO_PARENT, 1.0f, 				Animation.RELATIVE_TO_PARENT, 0.0f, 				Animation.RELATIVE_TO_PARENT, 1.0f);		ta.setDuration(2000);		ta.setRepeatCount(2);		ta.setRepeatMode(Animation.REVERSE);		lanucher.startAnimation(ta);	}		//透明度	public void alpha(View view)	{		AlphaAnimation an = new AlphaAnimation(0.0f, 1.0f);		an.setDuration(2000);		an.setRepeatCount(2);		an.setRepeatMode(Animation.REVERSE);		lanucher.startAnimation(an);	}		//缩放	public void scale(View view)	{		ScaleAnimation sa = new ScaleAnimation(0.2f, 2.0f, 0.2f, 2.0f, 				Animation.RELATIVE_TO_SELF, 0.5f, 				Animation.RELATIVE_TO_SELF, 0.5f);		sa.setDuration(2000);		sa.setRepeatCount(2);		sa.setRepeatMode(Animation.REVERSE);		lanucher.startAnimation(sa);	}		//旋转	public void rotate(View view)	{		RotateAnimation ra = new RotateAnimation(0, 360, 								Animation.RELATIVE_TO_SELF, 0.5f, 				Animation.RELATIVE_TO_SELF, 0.5f);		ra.setDuration(2000);		ra.setRepeatCount(2);		ra.setRepeatMode(Animation.REVERSE);		lanucher.startAnimation(ra);			}		//动画集合	public void set(View view)	{		AnimationSet set = new AnimationSet(false);				RotateAnimation ra = new RotateAnimation(0, 360, 								Animation.RELATIVE_TO_SELF, 0.5f, 				Animation.RELATIVE_TO_SELF, 0.5f);		ra.setDuration(2000);		ra.setRepeatCount(2);		ra.setRepeatMode(Animation.REVERSE);				TranslateAnimation ta = new TranslateAnimation(				Animation.RELATIVE_TO_PARENT, 0.0f, 				Animation.RELATIVE_TO_PARENT, 1.0f, 				Animation.RELATIVE_TO_PARENT, 0.0f, 				Animation.RELATIVE_TO_PARENT, 1.0f);		ta.setDuration(2000);		ta.setRepeatCount(2);		ta.setRepeatMode(Animation.REVERSE);		lanucher.startAnimation(ta);				set.addAnimation(ra);		set.addAnimation(ta);		lanucher.startAnimation(set);	}

##3. xml配置动画

  1. 透明度
  1. 旋转
  1. 缩放
  1. 平移
  1. 集合

程序片段

private ImageView xiv;	@Override	protected void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		setContentView(R.layout.xml_main);		xiv = (ImageView) findViewById(R.id.xiv);	}		//透明度	public void alpha(View view)	{		Animation am = AnimationUtils.loadAnimation(this, R.anim.alpha);		xiv.startAnimation(am);	}

转载于:https://my.oschina.net/u/729139/blog/480964

你可能感兴趣的文章
angular6 子组件向父组件通信
查看>>
flutter demo (四):对话框
查看>>
Redux compose()方法解析:
查看>>
JavaScript中Map与JSON转换要小心
查看>>
安卓手机上传图片后无响应
查看>>
Android防护扫盲篇
查看>>
spring 集成 webservice 进过反复测试终于完成了
查看>>
原型----《你不知道的js》
查看>>
关于Electron原生模块编译的一点总结
查看>>
小程序:模仿美团商品列表
查看>>
Angular学习笔记07——表单
查看>>
高价招ios和安卓APP马甲封装上架技术人员
查看>>
闭包、定时器
查看>>
iOS开发-面试小计(一)
查看>>
PHP 源码探秘 - 在解析外部变量时的一个问题
查看>>
手把手教你搭建微信小程序服务器(HTTPS)
查看>>
简析 Jenkins 专有用户数据库加密算法
查看>>
ios软键盘遮挡输入框问题
查看>>
在Git中配置多ssh key登陆不同仓库
查看>>
java B2B2C springmvc mybatis多租户电子商城系统-服务网关过滤器
查看>>