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 ——缩放动画效 ...
随机推荐
- 10分钟学会JAVA注解(annotation)
(原) 先认识注解(Annotation) 定义类用class,定义接口用interface,定义注解用@interface 如public @interface AnnotationTest{} 所 ...
- 点评阿里JAVA手册之编程规约(OOP 规约 、集合处理 、并发处理 、其他)
下载原版阿里JAVA开发手册 [阿里巴巴Java开发手册v1.2.0] 本文主要是对照阿里开发手册,注释自己在工作中运用情况. 本文难度系数为三星(★★★) 本文为第二篇 第一篇 点评阿里JAVA手 ...
- void main(), int main() 和int main(void)的区别
1.区别是main()函数是否有返回值.2.void定义的函数没有返回值,int定义的函数返回整型值.3.void,字面意思是"无类型",常用在程序编写中对定义函数的参数类型.返回 ...
- textarea placeholder文字换行
要实现这样的效果 第一反应是直接在placeholder属性值里输入\n换行,如: <textarea rows="5" cols="50" placeh ...
- [原创]使用logcat快速抓取android崩溃日志
在android APP测试过程中会发生不少的crash,目前抓取日志的主流方法是通过eclipse或者eclipse的ddms组件进行捕抓,这两种方法有个缺点是启动时非常耗时.本文通过adb程序与b ...
- 浅谈Android studio中OKHttp安装及简单使用
Google貌似在6.0版本里面删除了HttpClient相关API,鉴于okhttp的口碑相当好,介绍一下OKHttp的安装及使用: 一.安装 对于Android Studio的用户,在Projec ...
- servlet与Javabean之间的区别
在JSP中调用JAVA类和使用JavaBean有什么区别? 可以像使用一般的类一样使用JavaBean,Bean只是一种特殊的类.特殊在可以通过<jsp:useBean/>调用JavaBe ...
- 【错误】undefined reference to `boost::....的解决
很多新手引用Boost库编程,在ubuntu下编译时候有时候会出现如下错误: test04.cpp:(.text+0x2c): undefined reference to `boost::progr ...
- 初步探究java中程序退出、GC垃圾回收时,socket tcp连接的行为
初步探究java中程序退出.GC垃圾回收时,socket tcp连接的行为 今天在项目开发中需要用到socket tcp连接相关(作为tcp客户端),在思考中发觉需要理清socket主动.被动关闭时发 ...
- 实现Ant Design 自定义表单组件
Ant Design 组件提供了Input,InputNumber,Radio,Select,uplod等表单组件,但实际开发中这是不能满足需求,同时我们希望可以继续使用Form提供的验证和提示等方法 ...