安卓应用动画到一个视图创建的RuntimeException [英] Android: Applying an animation to a view creates RuntimeException

查看:154
本文介绍了安卓应用动画到一个视图创建的RuntimeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我的看法,从下面的例子ApiDemo设置动画(见layout_grid_fade.html):

 <?XML版本=1.0编码=UTF-8&GT?;
< gridLayoutAnimation的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:rowDelay =50%
        机器人:directionPriority =栏
        机器人:动画=@动画/淡出/>

和下面是我的code

  mView.startAnimation(AnimationUtils.loadAnimation(ViewModel.this,R.anim.layout_grid_fade));
mView.setImage(modelImages.get(0)图像配);

但我得到的异常不知道为什么?下面是我的日志跟踪

 致命异常:主要
了java.lang.RuntimeException:未知动画名称:gridLayoutAnimation
    在android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:116)
    在android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:83)
    在android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:64)
    在nick.kimK.ViewModel $ 1 $ 1.run(ViewModel.java:72)
    在android.os.Handler.handleCallback(Handler.java:587)
    在android.os.Handler.dispatchMessage(Handler.java:92)
    在android.os.Looper.loop(Looper.java:123)
    在android.app.ActivityThread.main(ActivityThread.java:4627)
    在java.lang.reflect.Method.invokeNative(本机方法)
    在java.lang.reflect.Method.invoke(Method.java:521)
    在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:871)
    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
    在dalvik.system.NativeStart.main(本机方法)


解决方案

UPD:
不RES /动画文件夹中每个XML声明的动画。他们中有些人可能会声明<一个href=\"http://developer.android.com/intl/zh-TW/reference/android/animation/Animator.html\">Animators或<一个href=\"http://developer.android.com/intl/zh-TW/reference/android/view/animation/LayoutAnimationController.html\">LayoutAnimationControllers.这些都不是动画,因此它们不能被装入 loadAnimation()电话。

-

它看起来像 gridLayoutAnimation 标签描述不是一个特定的基本动画类型,而是一个<一href=\"http://developer.android.com/intl/zh-TW/reference/android/view/animation/GridLayoutAnimationController.html\">GridLayoutAnimationController.因此,它可以直接与AnimationUtils.loadAnimation(装载),而是应设置为一个的ViewGroup(布局)throuh <一href=\"http://developer.android.com/reference/android/view/ViewGroup.html#attr_android%3alayoutAnimation\">layoutAnimation属性。如果你仍然想获得code中的AnimationController实例,使用<一个href=\"http://developer.android.com/intl/zh-TW/reference/android/view/animation/AnimationUtils.html#loadLayoutAnimation%28android.content.Context,%20int%29\">AnimationUtils.loadLayoutAnimation()方法:

  LayoutAnimationController layoutAnimation = AnimationUtils.loadLayoutAnimation(ViewModel.this,R.anim.layout_grid_fade)

但你几乎可以在你在你的例子做的方式layoutAnimation。
我发现<一个href=\"http://www.satyakomatineni.com/akc/display?url=displaynoteimpurl&ownerUserId=satya&reportId=2898\">this文章理解的布局动画中非常有用。

I am setting an animation on my view from following the ApiDemo example (see layout_grid_fade.html):

<?xml version="1.0" encoding="utf-8"?>
<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:rowDelay="50%"
        android:directionPriority="column"
        android:animation="@anim/fade" />

and below is my code

mView.startAnimation(AnimationUtils.loadAnimation(ViewModel.this, R.anim.layout_grid_fade));
mView.setImage(modelImages.get(0).image);

but i get exception dont know why? below is my log trace

FATAL EXCEPTION: main
java.lang.RuntimeException: Unknown animation name: gridLayoutAnimation
    at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:116)
    at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:83)
    at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:64)
    at nick.kimK.ViewModel$1$1.run(ViewModel.java:72)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4627)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
    at dalvik.system.NativeStart.main(Native Method)

解决方案

UPD: Not every xml in res/anim folder declares an animation. Some of them might declare Animators or LayoutAnimationControllers. Those are not Animations, thus they can't be loaded with the loadAnimation() call.

--

It looks like the gridLayoutAnimation tag describes not a particular basic animation type but rather a GridLayoutAnimationController. So it can be loaded directly with AnimationUtils.loadAnimation() but rather should be set to a ViewGroup (a layout) throuh layoutAnimation property. If you still want to obtain the AnimationController instance in code, use AnimationUtils.loadLayoutAnimation() method:

LayoutAnimationController layoutAnimation = AnimationUtils.loadLayoutAnimation(ViewModel.this, R.anim.layout_grid_fade)

But you hardly can use the layoutAnimation in the way you're doing in your example. I found this article quite useful for understanding the layout animations.

这篇关于安卓应用动画到一个视图创建的RuntimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆