在1.6之后,也就是从API 5开始,加入了一个overridePendingTransition函数,是用来处理Activity跳转时实现动画效果的。在网上,很多人发帖或者转发,只是很简单的提供了一种写法:
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) {
overridePendingTransition(R.anim.push_up_in,R.anim.push_up_out);
}
但是这种写法在项目中使用的话,会出现问题,在1.6的测试机器上会出现一个VerifyError的错误,因为overridePendingTransition 会在加载类加载时调用,在1.6的机器上会进行一个预编译,直接这样写就会出现错误。
在国外某论坛搜索了一下,发现了这样一段话:
The VM will attempt to find overridePendingTransition() when the class is loaded, not when that if() statement is executed.
Instead, you should be able to do this:
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) {
SomeClassDedicatedToThisOperation.overridePendingTransition(this, ...);
}
where the implementation of overridePendingTransition() in SomeClassDedicatedToThisOperation just calls overridePendingTransition() on the supplied Activity.
So long as SomeClassDedicatedToThisOperation is not used anywhere else, its class will not be loaded until you are inside your if() test, and you will not get the VerifyError.
这里已经很明确的给出了解决办法。
处理方式:
public class AnimationModel {
private Activity context;
public AnimationModel(Activity context){
this.context = context;
}
/**
* call overridePendingTransition() on the supplied Activity.
* @param a
* @param b
*/
public void overridePendingTransition(int a, int b){
context.overridePendingTransition(a, b);
}
}
调用方式:
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONU) {
(new AnimationModel(Profile.this))
.overridePendingTransition(R.anim.push_up_in,
R.anim.push_up_out);
}
这样,你引用跳转动画函数的模型类是生成了,但是里边的函数是不会被调用的。这样就不会被加载到jvm中去。问题也就解决了。
分享到:
相关推荐
activity跳转动画效果 轻松实现超炫跳转动画效果
通过overridePendingTransition方法实现Activity的跳转动画通过定义Application style实现Activity的跳转动画通过ActivityOptions代码实现...共享组件的方式实现Activity的过渡动画更多关于Activity跳转动画的知识...
Andriod_去掉系统自带的Activity跳转动画.
Android的Activity跳转动画
演示5.x之前Android的Activity跳转动画,以及Android5.x之后的跳转动画
集合了二十多种activity 跳转时的动画,各种玄丽效果。应有尽有,不下走宝了,你不会后悔!
Activity跳转动画大全,更加人性化的activity跳转效果,很有用!
其实Android的Activity跳转可以设置各种动画。下面给大家看看效果: 实现非常简单,用overridePendingtransition(int inId, int outId)即可实现。inId是下一界面进入效果的xml文件的id,outId是当前界面退出效果的xml...
Activity跳转动画终极版,包含左进,右进,底部进,顶部进,淡入,缩入。如果你刚好需要这方面东西,这个Demo绝对适合你。其中提供了封装进BaseActivity的思路。
实现activity跳转动画的简单Demo
android Lollipop(5.0的跳转动画),有共享view的activity跳转动画
实现activity绚丽的跳转动画效果,
网上找了一大堆的Android Activity跳转动画,大多都是抄袭,而且都是不完整,自己想要用的时候 还真麻烦,所以做了个demo,供自己用
android Activity跳转动画集合
Activity之间的跳转和返回显得比较突兀,如果能有动画衔接跳转和返回,就可以实现Iphone效果的界面切换效果了。
Activity之间动画跳转的demo,很简单的示例。
Activity页面跳转动画,拿来即用!
SwipeRefreshDemo-master201701231115各种activity跳转动画效果.zip