1

getViewTreeObserver and ObjectAnimator by using Nineoldandroids in api 8 doesn't work.

It work in higher API (Ex. API 19)

Here is my code.

        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();
            }
        });

HERE is my 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)

NOTE::

1) I have test between API8 and API 19.

2) I have test nineoldandroids (ObjectAnimator) in both API and it work.

3) I have test ObjectAnimator and view that get from getViewTreeObserver()

  • RESULT API 19 - WORK!, API 8 - Force Close;

4) I have try solution from this guy.

However,my force close gone but still animation doesn't play and there're somethings wrong in animation.

Community
  • 1
  • 1
Jongz Puangput
  • 5,527
  • 10
  • 58
  • 96

0 Answers0