Android中的动画效果
动画的种类
透明动画alphaAnimation
在代码中配置动画:
findViewById(R.id.btnAnimMe).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
alphaAnimation.setDuration(1000);
view.startAnimation(alphaAnimation);
}
});
在xml中配置动画:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0"
android:toAlpha="1"
android:duration="1000"> </alpha>
findViewById(R.id.btnAnimMe).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
view.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.aa));
}
});
旋转动画RoateAnimation
在代码中配置动画:
findViewById(R.id.btnRotateMe).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RotateAnimation rotateAnimation = new RotateAnimation(0, 360);
//相对于自身旋转
//RotateAnimation rotateAnimation = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(1000); view.startAnimation(rotateAnimation); } });
在xml中配置动画:
<?xml version="1.0" encoding="utf-8"?>
<rotate android:fromDegrees="0"
android:toDegrees="1"
android:duration="1000"
android:pivotX="50%"
android:pivotY="50%"
xmlns:android="http://schemas.android.com/apk/res/android"> </rotate>
view.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.ra));
移动动画translateAnimation
在代码中配置动画:
findViewById(R.id.btnTranslateMe).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//refer to self position
TranslateAnimation ta = new TranslateAnimation(0, 200, 0, 200);
ta.setDuration(1000);
view.startAnimation(ta);
}
});
在xml中配置动画:
<?xml version="1.0" encoding="utf-8"?>
<translate android:fromXDelta="0"
android:toXDelta="200"
android:fromYDelta="0"
android:toYDelta="200"
android:duration="1000"
xmlns:android="http://schemas.android.com/apk/res/android"> </translate>
view.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.ta));
缩放动画
在代码中配置动画:
findViewById(R.id.btnScaleMe).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1);
ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
sa.setDuration(1000);
view.startAnimation(sa);
}
});
在xml中配置动画:
<scale android:fromXScale="0"
android:toXScale="1"
android:fromYScale="0"
android:toYScale="1"
android:duration="1000"
android:pivotX="50%"
android:pivotY="50%"
xmlns:android="http://schemas.android.com/apk/res/android"> </scale>
view.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.sa));
动画混合
在代码中配置动画:
findViewById(R.id.btnAnimMe).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) { AnimationSet as = new AnimationSet(true);
as.setDuration(1000); AlphaAnimation aa = new AlphaAnimation(0, 1);
aa.setDuration(1000);
as.addAnimation(aa); TranslateAnimation ta = new TranslateAnimation(200, 0 , 200, 0);
ta.setDuration(1000);
as.addAnimation(ta); view.startAnimation(as); }
});
在xml中配置动画:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true"
android:duration="1000">
<alpha
android:fromAlpha="0"
android:toAlpha="1"/>
<translate
android:fromYDelta="200"
android:toYDelta="0"
android:fromXDelta="200"
android:toXDelta="0"/>
</set>
动画效果侦听
Animation a = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.sa);
a.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
Toast.makeText(MainActivity.this, "Animation Start", Toast.LENGTH_SHORT).show();
} @Override
public void onAnimationEnd(Animation animation) {
Toast.makeText(MainActivity.this, "Animation End", Toast.LENGTH_SHORT).show();
} @Override
public void onAnimationRepeat(Animation animation) { }
});
view.startAnimation(a);
自定义动画效果
自定义动画需要自定义一个类继承自Animation, 并重写applyTransformation. 在applyTransformation中,第一个参数interpolatedTime是一个0到1的变化范围。
- 如果调用Transform.setAlpha(interpolatedTime)就是一个透明的AlphaAnimation效果。
- 如果要设置移位的动画,可以通过getmetrix:
t.getMatrix().setTranslate(200*interpolatedTime, 200);
每一个动画执行前都会执行initalize。
Android中的动画效果的更多相关文章
- Android中矢量动画
Android中矢量动画 Android中用<path> 标签来创建SVG,就好比控制着一支画笔,从一点到一点,动一条线. <path> 标签 支持一下属性 M = (Mx, ...
- 初识android中的动画
动画效果可以大大提高界面的交互效果,因此,动画在移动开发中的应用场景较为普遍.掌握基本的动画效果在成熟的软件开发中不可或缺.除此之外,用户对于动画的接受程度远高于文字和图片,利用动画效果可以加深用户对 ...
- Android(java)学习笔记200:Android中View动画之 XML实现 和 代码实现
1.Animation 动画类型 Android的animation由四种类型组成: XML中: alph 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动 ...
- Android中的动画
Android中的动画分为: 1.逐帧动画(Frame Animation): 把动画过程的每张静态图片都收集起来,然后由Android来控制依次显示这些静态图片,然后利用人眼”视觉暂留“的原理,给 ...
- Android中的动画具体解释系列【4】——Activity之间切换动画
前面介绍了Android中的逐帧动画和补间动画,并实现了简单的自己定义动画.这一篇我们来看看怎样将Android中的动画运用到实际开发中的一个场景--Activity之间跳转动画. 一.定义动画资源 ...
- Android(java)学习笔记143:Android中View动画之 XML实现 和 代码实现
1.Animation 动画类型 Android的animation由四种类型组成: XML中: alph 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动 ...
- Android中的动画详解系列【4】——Activity之间切换动画
前面介绍了Android中的逐帧动画和补间动画,并实现了简单的自定义动画,这一篇我们来看看如何将Android中的动画运用到实际开发中的一个场景--Activity之间跳转动画. 一.定义动画资源 如 ...
- Android中的动画机制
1 逐帧动画 逐帧动画 就是一系列的图片按照一定的顺序展示的过程. 逐帧动画很简单, 只需要在drawable中或者anim中定义一个Animation-list 其中包含多个it ...
- Android中的动画学习总结
android中动画可分为三种:帧动画,补间动画,和属性动画.其中属性动画是google推荐的,它可以实现前面两种动画的效果,运用起来更加灵活. 帧动画:顾名思义,就是一帧一帧的图片,快速播放形成的动 ...
随机推荐
- C# WebService服务Post提交
public string WebServerTest(string PostData) { PostData = "jsonData=" + PostData; string P ...
- [poj2349]Arctic Network(最小生成树+贪心)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17758 Accepted: 5646 D ...
- VR视频外包公司(长年承接虚拟全景外包、虚拟现实视频外包)
承接VR视频外包(虚拟全景外包),虚拟现实视频外包(北京公司) 我们制作各类型VR全景虚拟现实,增强现实视频制作.录制等项目! 品质保证,售后完备. 我们团队成立于2011年10月,是一个专业从事严肃 ...
- (原创)vim配色------水果色,不伤眼。
- (原创)Windows系统后安装ubuntu,无法选择启动ubuntu。
继Window系统之后,安装Ubuntu系统. 问题:启动没有Grub的ubuntu启动项. 查看:/boot/grub/中只有txt和env,内容空白,grub没有设置好. 修复: sudo fdi ...
- 标准W3C盒子模型和IE盒子模型CSS布局经典盒子模型(转)
盒子模型是css中一个重要的概念,理解了盒子模型才能更好的排版.其实盒子模型有两种,分别是 ie 盒子模型和标准 w3c 盒子模型.他们对盒子模型的解释各不相同,先来看看我们熟知的标准盒子模型: 从上 ...
- centos 7 编译zabbix 3.2.2
已有LNMP环境. 1.安装zabbix需要的依赖包,红色部门的包官方yum源没有,需要自己下载 yum install net-snmp fping iksemel net-snmp-devel ...
- IntrospectorCleanupListener作用
<!--web.xml--><listener> <listener-class>org.springframework.web.util.Introspector ...
- zookeeper、kafka、storm install
安装顺序 zookeeper,kafka,storm install zookeeper 1.上传tar包,解压tar tar -zxvf zookeeper-3.4.6.tar.gz 2.复制 ...
- Sudoku 数独游戏
#include<iostream> using namespace std; bool heng(int **sudo, int a, int b, int value) { bool ...