在api 8中使用Nineoldandroids的getViewTreeObserver和ObjectAnimator不起作用

时间:2014-05-09 12:50:45

标签: android android-layout nineoldandroids

getViewTreeObserver和ObjectAnimator在api 8中使用Nineoldandroid并不起作用。

它适用于更高的API(例如API 19)

这是我的代码。

        final LayoutInflater inflater = (LayoutInflater)Home.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMessage = (TextView) inflater.inflate(R.layout.refresh_message, null);
        mMessage.setBackgroundColor(getResources().getColor(R.color.holo_green_light));
        mMessage.setText(msg);

        getWindowManager().addView(mMessage, getActionBarLayoutParams());

        mMessage.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){

            @Override
            public void onGlobalLayout() {
                // Get the height of the view
                final int h = mMessage.getHeight();
                //Remove Global Layout Listener
                removeOnGlobalLayoutListener(mMessage,this);
                // Slide down from the top
                ObjectAnimator.ofFloat(mMessage, "translationY", -h, 0f).setDuration(250).start();
            }
        });

这是我的LOGCAT ::

05-09 19:28:47.942      507-507/com.bis.org.auInsight E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.ClassCastException: android.view.ViewRoot
            at com.nineoldandroids.view.animation.AnimatorProxy.invalidateAfterUpdate(AnimatorProxy.java:245)
            at com.nineoldandroids.view.animation.AnimatorProxy.setTranslationY(AnimatorProxy.java:199)
            at com.nineoldandroids.animation.PreHoneycombCompat$5.setValue(PreHoneycombCompat.java:57)
            at com.nineoldandroids.animation.PreHoneycombCompat$5.setValue(PreHoneycombCompat.java:54)
            at com.nineoldandroids.util.FloatProperty.set(FloatProperty.java:43)
            at com.nineoldandroids.util.FloatProperty.set(FloatProperty.java:29)
            at com.nineoldandroids.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:967)
            at com.nineoldandroids.animation.ObjectAnimator.animateValue(ObjectAnimator.java:500)
            at com.nineoldandroids.animation.ValueAnimator.animationFrame(ValueAnimator.java:1139)
            at com.nineoldandroids.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:545)
            at com.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:928)
            at com.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:951)
            at com.nineoldandroids.animation.ObjectAnimator.start(ObjectAnimator.java:391)
            at com.bis.org.auInsight.Home$3.onGlobalLayout(Home.java:187)
            at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:549)
            at android.view.ViewRoot.performTraversals(ViewRoot.java:1094)
            at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            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:868)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
            at dalvik.system.NativeStart.main(Native Method)

请注意:

1)我在API8和API 19之间进行了测试。

2)我在两个API中测试了nineoldandroids(ObjectAnimator)并且它可以工作。

3)我有测试ObjectAnimator和来自getViewTreeObserver()的视图

  • RESULT API 19 - WORK!,API 8 - 强制关闭;

4)我尝试了guy的解决方案。

然而,我的力量已经消失,但动画仍然无法播放,而且动画中出现了一些错误。

0 个答案:

没有答案