Android -- Fragment动画异常Unknown animation name: objectAnimator
异常
Caused by: java.lang.RuntimeException: Unknown animation name: objectAnimator
异常代码
FragmentTransaction ft = getFragmentManager().beginTransaction();
//setCustomAnimations()必须位于replace()之前,否则效果不起所中。它的两个参数分别为enter,exit的效果。系统目前提供两个效果,分别为android.R.animator.fade_in和android.R.animator.fade_out
ft.setCustomAnimations(R.animator.slide_in_left,R.animator.slide_out_right);
ft.addToBackStack(null);
ft.replace(R.id.details,"detail");
ft.commit();
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:valueFrom="-1280"
android:valueTo="0"
android:valueType="floatType"
android:propertyName="X"
android:duration="2000" />
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:valueFrom="0"
android:valueTo="1280"
android:valueType="floatType"
android:propertyName="X"
android:duration="2000" />
动画简单说明
实现自定义动画的类是ObjectAnimator,不仅用于fragment,也可用于view。在xml中,定义了从“from”状态到“to”状态,时间间隔为duration(毫秒),所执行的变化规则称为interpolator。最简单的interpolator是linear,即@android:interpolator/linear,从状态From到to状态是均匀变化。缺省的interpolator是accelerate_decelerate。系统提供的方式可以在源代码/data/res/interpolator中查看。android:propertyName用于动画的维度,在本例中X表示横向,根view的setX()中的参数是float,所以设置valueType为floatType。我们设置可以设置自己的维度。From设置为-1280,因为这个值对于终端设备而言,-1280个像素位可以确保从不可视的位置移入。如果我们没有设置From,系统会根据当前值来设定初始值。
如果我们要在两个或者两个以上的维度设置变化,可以使用set tag,对应为Android的AnimatorSet类,下面的例子同时设置向下和淡出效果。set有一个属性android:ordering,缺省为together,即各个维度的变化同时发生,还可以设置为sequentially依次发生。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator android:interpolator="@android:interpolator/accelerate_cubic"
android:valueFrom="1"
android:valueTo="0"
android:valueType="floatType"
android:propertyName="alpha"
android:duration="1000"/>
<objectAnimator android:interpolator="@android:interpolator/accelerate_cubic"
android:valueFrom="0"
android:valueTo="1280"
android:valueType="floatType"
android:propertyName="Y"
android:duration="1000"/>
</set>
异常分析
V4包中的Fragment对于动画的支持不完全。
在FragmentManager类中的loadAnimation方法
if (transitionStyle == 0) {
return null;
}
//TypedArray attrs = mActivity.obtainStyledAttributes(transitionStyle,
// com.android.internal.R.styleable.FragmentAnimation);
//int anim = attrs.getResourceId(styleIndex, 0);
//attrs.recycle();
//if (anim == 0) {
// return null;
//}
//return AnimatorInflater.loadAnimator(mActivity, anim);
return null;
在AnimatorInflater.loadAnimator里面处理的动画:
String name = parser.getName();
if (name.equals("objectAnimator")) {
anim = loadObjectAnimator(c, attrs);
} else if (name.equals("animator")) {
anim = loadAnimator(c, attrs, null);
} else if (name.equals("set")) {
anim = new AnimatorSet();
TypedArray a = c.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.AnimatorSet);
int ordering = a.getInt(com.android.internal.R.styleable.AnimatorSet_ordering,
TOGETHER);
createAnimatorFromXml(c, parser, attrs, (AnimatorSet) anim, ordering);
a.recycle();
} else {
throw new RuntimeException("Unknown animator name: " + parser.getName());
}
private static ObjectAnimator loadObjectAnimator(Context context, AttributeSet attrs)
throws NotFoundException { ObjectAnimator anim = new ObjectAnimator(); loadAnimator(context, attrs, anim); TypedArray a =
context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.PropertyAnimator); String propertyName = a.getString(com.android.internal.R.styleable.PropertyAnimator_propertyName); anim.setPropertyName(propertyName); a.recycle(); return anim;
}
So
在使用V4包中Fragment时,使用的切换动画效果,其动画文件中不能包含objectAnimator,Animator这类标签。如果必须要使用,请将工程中使用的V4包中Fragment相关类,换成源码中的Fragment相关类。
我是天王盖地虎的分割线
Android -- Fragment动画异常Unknown animation name: objectAnimator的更多相关文章
- Android编程之Fragment使用动画造成Unknown animation name: objectAnimator异常
在为Fragment做切换动画.启动后遇到了一个异常: Caused by: java.lang.RuntimeException: Unknown animation name: objectAni ...
- Android 属性动画(Property Animation) 全然解析 (下)
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38092093 上一篇Android 属性动画(Property Animatio ...
- Android 属性动画(Property Animation) 完全解析 (下)
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38092093 上一篇Android 属性动画(Property Animatio ...
- 通过AnimationSet 同步或一部播放多个动画 Android 属性动画(Property Animation) 完全解析 (下)
AnimationSet提供了一个把多个动画组合成一个组合的机制,并可设置组中动画的时序关系,如同时播放,顺序播放等. 以下例子同时应用5个动画: 播放anim1: 同时播放anim2,anim3,a ...
- android:Fragment动画的东西
最近很多人来Fragment动画是很感兴趣,我将是一个样本给大家看. 既然做,我会做动画以下类型: 注入弹出动画:从""进入.从"上下左右"弹出,当然,你怎么组 ...
- Android 属性动画(Property Animation) 完全解析 (上)
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38067475 1.概述 Android提 供了几种动画类型:View Anima ...
- 【转】Android 属性动画(Property Animation) 完全解析 (上)
http://blog.csdn.net/lmj623565791/article/details/38067475 1.概述 Android提供了几种动画类型:View Animation .Dra ...
- Android 属性动画(Property Animation) 全然解析 (上)
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38067475 1.概述 Android提供了几种动画类型:View Animat ...
- 我的Android进阶之旅------>Android之动画之Frame Animation实例
============================首先看看官网上关于Frame animation的介绍================================ 地址:http://de ...
随机推荐
- 一列道出yield和生成器的真谛
均匀大小的块 def chunks(l, n): """Yield successive n-sized chunks from l.""" ...
- django数据库操作-增删改查-多对多关系以及一对多(外键)关系
一.一对多(外键) 例子:一个作者对应多本书,一本书只有一个作者 model代码: class Person(models.Model); name = models.CharField('作者姓名' ...
- [ 原创 ] Java基础9--final throw throws finally的区别
final修饰的类不可被继承,final修饰的方法可以被继承但不能被重写(覆盖) final用于可以声明属性和方法,分别表示属性的不可变及方法的不可覆盖.不是方法的不可继承 throw是用来明确地抛出 ...
- Javascript:window.close()不起作用?
一般的窗口关闭的JS如下写法: window.close() 但是呢,chrome,firefox等中有时候会不起作用. 改为下面的写法: window.open("about:blank& ...
- 希尔排序之Java实现
希尔排序之Java实现 一.方法一 package cn.com.zfc.lesson21.sort; /** * * @title ShellSort * @describe 希尔排序 1959 年 ...
- BZOJ3207 花神的嘲讽计划
hash值建主席树. 垃圾题面没有熟虑范围害我MLE——>RE. By:大奕哥 #include<bits/stdc++.h> #define unll unsigned long ...
- [CF1086E]Beautiful Matrix(容斥+DP+树状数组)
给一个n*n的矩阵,保证:(1)每行都是一个排列 (2)每行每个位置和上一行对应位置不同.求这个矩阵在所有合法矩阵中字典序排第几.考虑类似数位DP的做法,枚举第几行开始不卡限制,那么显然之前的行都和题 ...
- wikioi 1294 全排列 dfs
1294 全排列 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给出一个n, 请输出n的所有全排列 输入描述 Inpu ...
- Android 5.0 源代码结构
本节书摘来自异步社区<深入理解Android 5 源代码>一书中的第2章,第2.2节分析Android源代码结构,作者 李骏. 网址:https://yq.aliyun.com/artic ...
- WCF实现将服务器端的错误信息返回到客户端
转载:http://www.cnblogs.com/zeroone/articles/2299001.html http://www.it165.net/pro/html/201403/11033.h ...