接上篇《android开发艺术探索》读书笔记(六)--Drawable

No1:

自定义动画:派生一种新动画只需要继承Animation这个抽象类,然后重写它的initialize和applyTransformation方法,在initialize方法中做一些初始化工作,在applyTransformation中进行相应的矩阵变换即可,很多时候需要采用Camera来简化矩阵变换的过程。

No2:

 
 
No3:                                                                                                                                                                                                                                                                                       
LayoutAnimation:LayoutAnimation作用于ViewGroup,为ViewGroup指定一个动画,这样当它的子元素出场时都会具有这种动画效果。这种效果常常被用在ListView上。
//res/anim/anim_layout.xml
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/anim_item"
android:animationOrder="normal"
android:delay="0.5" />
//res/anim/anim_item.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0" />
<translate
android:fromXDelta="1000"
android:toXDelta="0" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.administrator.layoutanimation.MainActivity"> <ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff4f7f9"
android:cacheColorHint="#00000000"
android:divider="#dddbdb"
android:dividerHeight="1.0px"
android:layoutAnimation="@anim/anim_layout"
android:listSelector="@android:color/transparent" />
</RelativeLayout>

还可通过LayoutAnimationController来实现

ListView listView = (ListView) findViewById(R.id.list);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim_item);
LayoutAnimationController controller = new LayoutAnimationController(animation);
controller.setDelay(0.5f);
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
listView.setLayoutAnimation(controller);

No4:

Activity切换效果,主要用到overridePendingTransition(int enterAnim,int exitAnim),此方法必须在startActivity(Intent)或者finish()之后调用才能生效

enterAnim--Activity被打开时,所需的动画资源id

exitAnim--Activity被暂停时,所需的动画资源id

Fragment切换动画,可以通过FragmentTransaction中的setCustomAnimations()方法来实现。切换动画需要是View动画

No5:

属性动画可以对任意对象的属性进行动画而不仅仅是View,可以采用开源动画库nineoldandroids来兼容以前的版本

No6:

TimeInterpolator时间插值器,它的作用是根据时间流逝的百分比来计算出当前属性值改变的百分比。

TypeEvaluator类型估值算法(估值器),它的作用是根据当前属性改变的百分比来计算改变后的属性值。

自定义插值器需要实现Interpolator或者TimeInterpolator,自定义估值算法需要实现TypeEvaluator。

No7:
AnimatorListener可以监听动画的开始、结束、取消和重复播放。
AnimatorUpdateListener可以监听整个过程,动画每播放一帧,onAnimationUpdate就会被调用一次。
No8:
我们对object的属性abc做动画,如果想让动画生效,需要同时满足两个条件
1)object必须要提供setAbc方法,如果动画的时候没有传递初始值,那么还要提供getAbc方法,因为系统要去取abc属性的初始值(如果这条不满足,程序直接Crash)
2)object的setAbc对属性abc所做的改变必须能够通过某种方式反映出来,比如会带来UI的改变之类的(如果这条不满足,动画无效果但不会Crash)
解决不满足条件二的方法:
private void performAnimate(){
ViewWrapper wrapper = new ViewWrapper(mButton);
ObjectAnimator.ofInt(wrapper,"width"500).setDuration(5000).start();
} @Override
public void onClick(View v){
if(v == mButton){
performAnimate();
}
} private static class ViewWrapper{
private View mTarget; public ViewWrapper(View target){
mTarget = target;
} public void setWidth(int width){
mTarget.getLayoutParams().width = width;
mTarget.requestLayout();
}
}

No9:

ValueAnimator监听动画过程,本身不作用于任何对象。它可以对一个值做动画,然后我们可以监听其动画过程,在动画过程中修改我们的对象的属性值,这样也就相当于我们的对象做了动画。

No10:

使用动画注意事项:

1)OOM--帧动画图片数量较多且图片较大时就极易出现OOM

2)内存泄露--无限循环属性动画需要在Activity退出时及时停止,否则导致Activity无法释放从而造成内存泄露,View动画不存在此问题

3)兼容--动画在3.0以下系统有兼容性问题

4)需要使用px--尽量别使用dp

5)动画元素交互--属性动画和View动画的单击事件触发位置

6)硬件加速--硬件加速会提高动画的流畅性

《android开发艺术探索》读书笔记(七)--动画的更多相关文章

  1. Android开发艺术探索读书笔记——01 Activity的生命周期

    http://www.cnblogs.com/csonezp/p/5121142.html 新买了一本书,<Android开发艺术探索>.这本书算是一本进阶书籍,适合有一定安卓开发基础,做 ...

  2. Android开发艺术探索读书笔记——进程间通信

    1. 多进程使用场景 1) 应用某些模块由于特殊需求须要执行在单独进程中. 如消息推送,使消息推送进程与应用进程能单独存活,消息推送进程不会由于应用程序进程crash而受影响. 2) 为加大一个应用可 ...

  3. android开发艺术探索读书笔记之-------view的事件分发机制

    View的点击事件的分发,其实就是对MotionEvent事件的分发过程,即当一个MotionEvent产生后,系统需要把这个事件传递给一个具体的View,而这个过程就是分发过程. 分发过程主要由以下 ...

  4. Android开发艺术探索学习笔记(三)

    第三章  View的事件体系 3.1 View基础知识 3.1.1 什么是view View 是Android中所有控件的基类,是一种界面层的控件的一种抽象,它代表了一个控件. 3.1.2 View的 ...

  5. Android开发艺术探索学习笔记(四)

    第四章 View的工作原理 4.1初识ViewRoot和DecorView ViewRoot是连接WindowManager和DecorView的纽带,View的三大流程均是通过ViewRoot来完成 ...

  6. Android开发艺术探索学习笔记(十一)

    第十一章  Android的线程和线程池 从用途上来说,线程分为子线程和主线程,主线程主要处理和界面相关的事情,而子线程往往用于执行耗时的操作.AsyncTask,IntentService,Hand ...

  7. Android开发艺术探索学习笔记(十)

    第十章  Android的消息机制 面试中经常会被问到的一个问题:handler是如何在子线程和主线程中进行消息的传递的,这个问题通过了解Android的消息机制可以得到一个准确的答案. Androi ...

  8. Android开发艺术探索学习笔记(六)

    第六章 Android的Drawable  Drawable的优点:使用简单,比自定义view的成本要低:非图片类型的Drawable占用空间小,有利于减小APK安装包的大小. 6.1Drawable ...

  9. Android开发艺术探索学习笔记(一)

    第一章 Activity的生命周期和启动模式 1.1Activity的生命周期全面解析 1.1.1典型情况下的生命周期分析 (1)在两个Activity进行切换时,当前的Activity的onPaus ...

  10. 《Android开发艺术探索》读书笔记 (9) 第9章 四大组件的工作过程

    第9章 四大组件的工作过程 9.1 四大组件的运行状态 (1)四大组件中只有BroadcastReceiver既可以在AndroidManifest文件中注册,也可以在代码中注册,其他三个组件都必须在 ...

随机推荐

  1. vs2005配置OpenCv2.3.1

    编译OpenCv 1 用CMake导出VC++项目文件 运行cmake-gui,设置where is the source code路径为OpenCV安装路径(本文档假定安装位置为:c:\OpenCV ...

  2. python 中 reversed()函数

    一个列表a: a=[1,2,3,4,5,6,7] 一个对象b: b=reversed(a) 输出: print(b) <list_reverseiterator object at 0x0000 ...

  3. Linux下安装mysql(yum和源码编译两种方式)

    这里介绍Linux下两种安装mysql的方式:yum安装和源码编译安装. 1. yum安装 (1)首先查看centos自带的mysql是否被安装: # yum list installed |grep ...

  4. Spring MVC (JDK8+Tomcat8)

    1 Spring MVC概述 Spring MVC是Spring为表现层提供的基于MVC设计理念的优秀的web框架,是目前最主流的MVC框架之一. Spring3.0后全面超越Struts2,成为最优 ...

  5. Struts2 (三)

    1 Struts2的拦截器 Struts2拦截器在访问某个Action方法之前或之后实施拦截,拦截器是可插拔的,拦截器是AOP的一种实现. Struts2拦截器栈:将拦截器按一定顺序联结成一条链,在访 ...

  6. awk的+=用法

    awk增加统计列值为增加列数或进行运行结果统计,使用符号 + =.增加的结果赋给符号左边变量值,增加到变量的域在符号右边.例如将 $ 1加入变量total,表达式为toatl+=$1.列值增加很有用. ...

  7. Cisco配置aaa验证

    当您的网络中部署了一台集中的radius校验服务器(比如我司的SAM,cisco的ACS等),希望对登陆设备的用户身份进行合法性校验,而账号都统一由该radius服务器集中产生与维护,您希望所有的登入 ...

  8. IOS 时间字符串转换时间戳失败问题

    链接:https://pan.baidu.com/s/1nw6VWoD 密码:1peh 有时候获取到的时间带有毫秒数或者是(2018-2-6 11:11:11)格式的(别说你没遇到过,也别什么都让后台 ...

  9. spring之setter注入

    setter注入分为2种 第一:普通属性注入 <bean id="userAction" class="com.xx.action.UserAction" ...

  10. 利用rsync+inotify实现数据实时同步脚本文件

    将代码放在Server端,实现其它web服务器同步.首先创建rsync.shell,rsync.shell代码如下: #!/bin/bash host1=133.96.7.100 host2=133. ...