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 ...
随机推荐
- python opencv3 背景分割 mog2 knn
git:https://github.com/linyi0604/Computer-Vision 使用mog2算法进行背景分割 # coding:utf-8 import cv2 # 获取摄像头对象 ...
- python装饰器原理
妙处在于装饰器的两个return 1.装饰器 # 使用闭包 def wrap(fun): def check(): print("正在检查用户权限!") fun() return ...
- 【POJ】2796:Feel Good【单调栈】
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18449 Accepted: 5125 Case T ...
- Codeforces Round #353 (Div. 2) C. Money Transfers 数学
C. Money Transfers 题目连接: http://www.codeforces.com/contest/675/problem/C Description There are n ban ...
- TensorFlow安装和HelloWorld
TensorFlow安装 TensorFlow可以在各种操作系统上面安装.安装的时候要注意TensorFlow的类型,一种是普通的版本,仅支持CPU,安装简单.另外一种类型带GPU的,可以利用GPU来 ...
- maven 自动部署到 tomcat7
多方搜索,终于使maven项目可以自动发布到tomcat下了. tomcat7 需要使用 tomcat-maven-plugin 的新版本,版本支持tomcat6和tomcat7,groupId也由o ...
- USB ISP(ICSP) Open Programmer < PWM ADC HV PID >
http://sourceforge.net/projects/openprogrammer/?source=navbar Open Programmer http://openprog.alterv ...
- mysql slock
http://www.itdks.com/dakashuo/new/dakalive/detail/3888
- cocos2d-x3.0 RichText
.h #include "cocos2d.h" #include "cocos-ext.h" #include "ui/CocosGUI.h" ...
- redis java操作
Redis Java连接操作 连接到Redis服务器 import redis.clients.jedis.Jedis; public class RedisJava { public static ...