布局文件:

<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补间动画笔记的更多相关文章

  1. android 补间动画和Animation

    介绍: 补间动画是一种设定动画开始状态.结束状态,其中间的变化由系统计算补充.这也是他叫做补间动画的原因. 补间动画由Animation类来实现具体效果,包括平移(TranslateAnimation ...

  2. android 补间动画

    android开发过程中,为了更好的展示应用程序,应用程序添加动画,能够很好地实现这个功能.如果动画中的图像变化有一定的规律,可以采用自动生成图像的方式来生成动画,例如图像的移动.旋转.缩放等.自动生 ...

  3. (原)android补间动画(四)之插补器Interpolator

    比如说一段旋转动画 RotateAnimation animation = new RotateAnimation(0, 360, mMoveCircle.getMeasuredWidth() / 2 ...

  4. Android补间动画、帧动画和属性动画使用知识介绍

    https://blog.csdn.net/zhangqunshuai/article/details/81098062

  5. Android 学习笔记多媒体技术之 Drawable类+Tween(补间动画)+Frame(帧动画)

    学习内容: 1.了解Drawable类的作用 2.如何使用Drawable... 3.了解Tween动画... 4.如何创建和使用Tween动画... 1.Drawable类...   Drawabl ...

  6. Android(java)学习笔记199:Android中补间动画(Tween Animation)

    本文主要简单介绍补间动画使用代码实现, 关于使用xml实现补间动画,可以参看:自定义控件三部曲之动画篇(一)——alpha.scale.translate.rotate.set的xml属性及用法 1. ...

  7. Android基础笔记(十)- 帧动画、补间动画具体解释、对话框

    帧动画 补间动画Tween Animation 对话框以及面试中的注意点 帧动画 帧动画非常easy,我们首先看一下Google官方解释This is a traditional animation ...

  8. Android(java)学习笔记142:Android中补间动画(Tween Animation)

    本文主要简单介绍补间动画使用代码实现, 关于使用xml实现补间动画, 可以参看:自定义控件三部曲之动画篇(一)——alpha.scale.translate.rotate.set的xml属性及用法 1 ...

  9. Android笔记(六十四) android中的动画——补间动画(tweened animation)

    补间动画就是只需要定义动画开始和结束的位置,动画中间的变化由系统去补齐. 补间动画由一下四种方式: 1.AplhaAnimation——透明度动画效果 2.ScaleAnimation ——缩放动画效 ...

随机推荐

  1. 多线程编程-- part 5.3 LockSupport

    一.LockSupport的介绍 LockSupport是用来创建锁和其他同步类的基本线程阻塞原语.  LockSupport中的park() 和 unpark() 的作用分别是阻塞线程和解除阻塞线程 ...

  2. 一天搞定CSS: 浮动(float)的副作用--12

    我们通常使用浮动来实现某些元素的布局,但是往往这些元素浮动会影响其他元素的布局,因此会产生副作用. 如果你还不清楚什么是浮动,那就点开这个链接: http://blog.csdn.net/baidu_ ...

  3. Eclipse设置文字大小

    1,选择窗口,preference 2,general

  4. numpy中linspace用法 (等差数列创建函数)

    linspace  函数 是创建等差数列的函数, 最好是在 Matlab  语言中见到这个函数的,近期在学习Python 中的 Numpy, 发现也有这个函数,以下给出自己在学习过程中的一些总结. ( ...

  5. 如何编写Spring-Boot自动配置

    摘要 本文主要介绍如何把一个spring的项目(特别是一些公共工具类项目),基于spring boot的自动配置的思想封装起来,使其他Spring-Boot项目引入后能够进行快速配置. AutoCon ...

  6. SQL SERVER 自动生成 MySQL 表结构及索引 的建表SQL

          SQL SERVER的表结构及索引转换为MySQL的表结构及索引,其实在很多第三方工具中有提供,比如navicat.sqlyog等,但是,在处理某些数据类型.默认值及索引转换的时候,总有些 ...

  7. 每天一个JS 小demo之个人信息添加。主要知识点:DOM操作中的表格操作,节点操作

    以下是简易效果: <!DOCTYPE html><html lang="en"><head> <meta charset="UT ...

  8. python+selenium遇到鼠标悬停不成功可以使用js进行操作

    问题:在定位这种悬停后出现下拉操作的时候,尝试了使用move_to_element的方法 # ele_logout = br.find_element_by_xpath('/html/body/div ...

  9. Analog/digital converter (ADC)

    1.ADC1 and ADC2 are 10-bit successive approximation Anolog to Digital Converters. 所谓successive appro ...

  10. .NET ORM框架 SqlSuagr4.0 功能详解与实践【开源】

    SqlSugar 4.0 ORM框架的优势 为了未来能够更好的支持多库分布式的存储,并行计算等功能,将SqlSugar3.x全部重写,现有的架构可以轻松扩展多库. 源码下载: https://gith ...