博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
安卓动画基础讲解
阅读量:4308 次
发布时间:2019-06-06

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

//逐帧动画
/**
* 1.加入单张图片
* 2.生成movie.xml整个图片
* 3.代码中使用图片movie.xml
*/
iv=(ImageView) findViewById(R.id.iv);
// iv.setImageResource(R.drawable.movie);//为iv加载六张图片
// AnimationDrawable ad=(AnimationDrawable) iv.getDrawable();//得到图片给动画图片
// ad.start();
DisplayMetrics dm = new DisplayMetrics();
getWindow().getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;//得到屏幕宽度
//补间动画,平移
//1.通过代码直接写
// Animation translate=new TranslateAnimation(0, width, 0, 0);
// translate.setDuration(2000);
// translate.setFillAfter(true);//动画完成后,留在原位
// translate.setRepeatCount(2);//重复2次
// translate.setStartOffset(1000);//等待1秒后再动
// iv.startAnimation(translate);
//2.调用xml文件
Animation translate=AnimationUtils.loadAnimation(this, R.anim.push_to_right);
iv.startAnimation(translate);
//iv.setAnimation(translate);也行
//动画监听事件
translate.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
Intent intent=new Intent(MainActivity.this,SecondAty.class);
startActivity(intent);
finish();
}
});
}

 

// 旋转动画

// 角度从0到360,pivotXType取谁的X值(界面的?就自身这个图片) pivotYType
// Animation rotator = new RotateAnimation(0, 360,
// RotateAnimation.RELATIVE_TO_SELF, 0.5f,
// RotateAnimation.RELATIVE_TO_SELF, 0.5f);
// rotator.setDuration(3000);
// rotator.setFillAfter(true);
// iv.startAnimation(rotator);

// 渐变

// Animation alpha = new AlphaAnimation(0, 0.9f);//从看不见到看到90%
// alpha.setDuration(3000);
// alpha.setFillAfter(true);
// iv.startAnimation(alpha);

// 拉伸

// fromX, toX, fromY, toY平移动画的四个参数,x轴伸缩尺寸,y轴伸缩尺寸
//ScaleAnimation.RELATIVE_TO_SELF, 3f//X轴坐标是自己图片宽度的3倍
Animation scale = new ScaleAnimation(0, 0.3f, 0, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 3f,
ScaleAnimation.RELATIVE_TO_SELF, 3f);
scale.setDuration(3000);
scale.setFillAfter(true);
iv.startAnimation(scale);

转载于:https://www.cnblogs.com/wangfeng520/p/5105015.html

你可能感兴趣的文章
京东技术架构(一)构建亿级前端读服务
查看>>
php 解决json_encode中文UNICODE转码问题
查看>>
LNMP 安装 thinkcmf提示404not found
查看>>
PHP empty、isset、innull的区别
查看>>
apache+nginx 实现动静分离
查看>>
通过Navicat远程连接MySQL配置
查看>>
phpstorm开发工具的设置用法
查看>>
Linux 系统挂载数据盘
查看>>
Git基础(三)--常见错误及解决方案
查看>>
Git(四) - 分支管理
查看>>
PHP Curl发送数据
查看>>
HTTP协议
查看>>
HTTPS
查看>>
git add . git add -u git add -A区别
查看>>
apache下虚拟域名配置
查看>>
session和cookie区别与联系
查看>>
PHP 实现笛卡尔积
查看>>
Laravel中的$loop
查看>>
CentOS7 重置root密码
查看>>
Centos安装Python3
查看>>