Android补间动画笔记
布局文件:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_my_anim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.jogger.propertiesanim.MyAnim"> <ImageView
android:id="@+id/iv_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/t_clock"/> <ImageView
android:id="@+id/iv_bettery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/t_bettery"/> <ImageView
android:id="@+id/iv_low_bettery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/iv_clock"
android:layout_centerHorizontal="true"
android:src="@drawable/t_low_bettery"/>
<ImageView
android:id="@+id/iv_next"
android:layout_centerHorizontal="true"
android:src="@drawable/t_next"
android:layout_below="@id/iv_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/iv_msg"
android:layout_centerHorizontal="true"
android:src="@drawable/t_first_msg"
android:layout_below="@id/iv_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/> </RelativeLayout>
方法一:动态注册
public class MyAnim extends AppCompatActivity {
private ImageView iv_low_bettery, iv_next, iv_bettery;
/**
* 补间动画案例(缩放,平移,旋转)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_anim);
iv_low_bettery = (ImageView) findViewById(R.id.iv_low_bettery);
iv_next = (ImageView) findViewById(R.id.iv_next);
iv_bettery = (ImageView) findViewById(R.id.iv_bettery);
//缩放动画
/**
* fromX:开始缩放的X轴倍数。如1.0f:本身大小;如2.0f:从自己两倍开始
toX:结束缩放的X轴倍数,体现在结束时的宽度上
fromY:始缩放的Y轴倍数。
toY:结束缩放的Y轴倍数。
pivotXType:X轴缩放中心点类型;可选值有:
Animation.RELATIVE_TO_SELF相对自己--常用
Animation.RELATIVE_TO_PARENT相对父窗体
Animation.ABSOLUTE 绝对的---不常用
pivotXValue:在pivotXType的基础上,X轴缩放中心的位置。如:0.5f:缩放中心就在控件的一半的位置。如果是0.0f,则会在控件本身的左边位置
pivotYType:X轴缩放中心点类型;同上 ...
pivotYValue:在pivotYType的基础上,Y轴缩放中心的位置。
*/
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 1.5f, 1.0f, 1.5f, Animation
.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//平移动画
/**
* fromXType:开始平移的X轴参照位置,一般使用Animation.RELATIVE_TO_SELF
fromXValue:X轴平移的开始倍数。在fromXType的基础上。
toXType:结束平移的X轴参照位置
toXValue:X轴平移的结束倍数。
fromYType:开始平移的Y轴参照位置
fromYValue:Y轴平移的开始倍数。
toYType:结束平移的Y轴参照位置
toYValue:Y轴平移的结束倍数。
*/
TranslateAnimation translateAnimation = new TranslateAnimation(Animation
.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF,
0, Animation.RELATIVE_TO_SELF, 1f);
scaleAnimation.setRepeatCount(Animation.INFINITE);//设置重复次数,INFINITE为设置无限重复
translateAnimation.setRepeatCount(Animation.INFINITE);
AnimationSet set = new AnimationSet(false);
set.addAnimation(scaleAnimation);
set.addAnimation(translateAnimation);
set.setDuration(2000);//播放一轮动画的时间
set.setRepeatMode(Animation.REVERSE);//用于设置动画的重复方式,可选择为reverse(反向)和restart(重新开始)
//set.setRepeatCount(Animation.INFINITE);//set不能直接设置无限重复
iv_low_bettery.startAnimation(set);
TranslateAnimation translateAnimationNext = new TranslateAnimation(Animation
.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF,
0, Animation.RELATIVE_TO_SELF, 1.1f);
translateAnimationNext.setDuration(2000);
translateAnimationNext.setRepeatCount(Animation.INFINITE);
translateAnimationNext.setRepeatMode(Animation.REVERSE);
iv_next.startAnimation(translateAnimationNext);
/**
* fromDegrees:开始旋转的角度;三点方向为0度,六点方向为90度。
toDegrees:结束旋转的角度
pivotXType:参照缩放动画
pivotXValue:参照缩放动画
pivotYType:参照缩放动画
pivotYValue:参照缩放动画
*/
RotateAnimation rotateAnimation = new RotateAnimation(0, 360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
rotateAnimation.setRepeatMode(Animation.REVERSE);
rotateAnimation.setRepeatCount(Animation.INFINITE);
rotateAnimation.setDuration(2000);
iv_bettery.startAnimation(rotateAnimation);
}
}
方法二:静态注册
在res目录下创建anim文件夹,创建如下3个资源文件:
low_bettery_anim.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:repeatMode="reverse"
>
<translate
android:fromXDelta="0"
android:fromYDelta="0"
android:repeatCount="infinite"
android:toXDelta="0"
android:toYDelta="100%"></translate>
<scale
android:fromXScale="100%"
android:fromYScale="100%"
android:pivotX="50%"
android:pivotY="50"
android:repeatCount="infinite"
android:toXScale="150%"
android:toYScale="150%"></scale>
</set> next_anim.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:repeatMode="reverse"> <translate
android:fromXDelta="0"
android:fromYDelta="0"
android:repeatCount="infinite"
android:toXDelta="0"
android:toYDelta="100%"></translate>
</set>
bettery_anim.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:repeatMode="reverse">
<!--pivotX 50%表示相对自身-->
<rotate
android:fromDegrees="0.5"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toDegrees="360"></rotate> </set>
代码界面:
public class MyAnim extends AppCompatActivity {
private ImageView iv_low_bettery, iv_next, iv_bettery;
/**
* 补间动画案例(缩放,平移,旋转)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_anim);
iv_low_bettery = (ImageView) findViewById(R.id.iv_low_bettery);
iv_next = (ImageView) findViewById(R.id.iv_next);
iv_bettery = (ImageView) findViewById(R.id.iv_bettery);
Animation low_bettery_anim = AnimationUtils.loadAnimation(this, R.anim.low_bettery_anim);
Animation next_anim = AnimationUtils.loadAnimation(this, R.anim.next_anim);
Animation bettery_anim = AnimationUtils.loadAnimation(this, R.anim.bettery_anim);
iv_next.startAnimation(next_anim);
iv_low_bettery.startAnimation(low_bettery_anim);
iv_bettery.startAnimation(bettery_anim);
}
}
效果图:
Android补间动画笔记的更多相关文章
- android 补间动画和Animation
介绍: 补间动画是一种设定动画开始状态.结束状态,其中间的变化由系统计算补充.这也是他叫做补间动画的原因. 补间动画由Animation类来实现具体效果,包括平移(TranslateAnimation ...
- android 补间动画
android开发过程中,为了更好的展示应用程序,应用程序添加动画,能够很好地实现这个功能.如果动画中的图像变化有一定的规律,可以采用自动生成图像的方式来生成动画,例如图像的移动.旋转.缩放等.自动生 ...
- (原)android补间动画(四)之插补器Interpolator
比如说一段旋转动画 RotateAnimation animation = new RotateAnimation(0, 360, mMoveCircle.getMeasuredWidth() / 2 ...
- Android补间动画、帧动画和属性动画使用知识介绍
https://blog.csdn.net/zhangqunshuai/article/details/81098062
- Android 学习笔记多媒体技术之 Drawable类+Tween(补间动画)+Frame(帧动画)
学习内容: 1.了解Drawable类的作用 2.如何使用Drawable... 3.了解Tween动画... 4.如何创建和使用Tween动画... 1.Drawable类... Drawabl ...
- Android(java)学习笔记199:Android中补间动画(Tween Animation)
本文主要简单介绍补间动画使用代码实现, 关于使用xml实现补间动画,可以参看:自定义控件三部曲之动画篇(一)——alpha.scale.translate.rotate.set的xml属性及用法 1. ...
- Android基础笔记(十)- 帧动画、补间动画具体解释、对话框
帧动画 补间动画Tween Animation 对话框以及面试中的注意点 帧动画 帧动画非常easy,我们首先看一下Google官方解释This is a traditional animation ...
- Android(java)学习笔记142:Android中补间动画(Tween Animation)
本文主要简单介绍补间动画使用代码实现, 关于使用xml实现补间动画, 可以参看:自定义控件三部曲之动画篇(一)——alpha.scale.translate.rotate.set的xml属性及用法 1 ...
- Android笔记(六十四) android中的动画——补间动画(tweened animation)
补间动画就是只需要定义动画开始和结束的位置,动画中间的变化由系统去补齐. 补间动画由一下四种方式: 1.AplhaAnimation——透明度动画效果 2.ScaleAnimation ——缩放动画效 ...
随机推荐
- 如何优雅地实现Python通用多线程/进程并行模块
当单线程性能不足时,我们通常会使用多线程/多进程去加速运行.而这些代码往往多得令人绝望,需要考虑: 如何创建线程执行的函数? 如何收集结果?若希望结果从子线程返回主线程,则还要使用队列 如何取消执行? ...
- 微信小程序开发《二》:http请求的session管理
作为一个开发JavaWeb应用的程序猿,都喜欢将用户登录后的用户信息(比如说用户id,用户名称)放入session中保存,之后在业务逻辑的开发中需要用到用户信息的时候就可以轻松又方便的从session ...
- 【Windows 10 应用开发】如何防止应用程序被截屏
今天老周只想跟大伙们分享一个小技巧,是的,小小的技巧,很简单,保证你能学会的,要是学不会,可以考虑跳泰山. 有些时候,我们可能会想到不要让应用程序界面上显示的内容被截屏,要阻止应用界面呈现在截图上,可 ...
- 如何按内容筛选dom
有时候我们需要按照dom的text内容去筛选,那么可以用jQuery的contains筛选 写法 $("div:contains(aaa)") 筛选出内容包含aaa的div 另外 ...
- 设计模式的征途—8.桥接(Bridge)模式
在现实生活中,我们常常会用到两种或多种类型的笔,比如毛笔和蜡笔.假设我们需要大.中.小三种类型的画笔来绘制12中不同的颜色,如果我们使用蜡笔,需要准备3*12=36支.但如果使用毛笔的话,只需要提供3 ...
- 关于Myeclipse不能加载已有项目的问题
如果缺少.project文件,你可以新建一个同名项目,把Use default location 去掉,选择要加载的项目,完成
- 将页面内容转换Pdf\Word\Excel格式
项目中用到了将邮件内容转换为Pdf.Word.Excel格式,做为邮件附件发送. 查了一些解决方案,走了一些弯路.以此代码记录下. 转换PDF需要下载NReco.PdfGenerator.dll 以下 ...
- [编织消息框架][netty源码分析]4 eventLoop 实现类NioEventLoop职责与实现
NioEventLoop 是jdk nio多路处理实现同修复jdk nio的bug 1.NioEventLoop继承SingleThreadEventLoop 重用单线程处理 2.NioEventLo ...
- swiper.js 碰到的坑
1. swiper隐藏之后,再显示,滑动不流畅,且无限滑动会失败: 解决方法: 添加一下两个属性 observer: true,//修改swiper自己或子元素时,自动初始化swiper observ ...
- vue全家桶(Vue+Vue-router+Vuex+axios)(Vue+webpack项目实战系列之二)
Vue有多优秀搭配全家桶做项目有多好之类的咱就不谈了,直奔主题. 一.Vue 系列一已经用vue-cli搭建了Vue项目,此处就不赘述了. 二.Vue-router Vue的路由,先献上文档(http ...
