1

所以这是我的 LogCat 崩溃报告(注意没有对我的代码的引用):

08-27 13:04:36.307    8073-8073/com.example.mysandbox E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.NullPointerException
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2919)
    at android.view.View.getDisplayList(View.java:12833)
    at android.view.View.getDisplayList(View.java:12880)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057)
    at android.view.View.getDisplayList(View.java:12775)
    at android.view.View.getDisplayList(View.java:12880)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057)
    at android.view.View.getDisplayList(View.java:12775)
    at android.view.View.getDisplayList(View.java:12880)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057)
    at android.view.View.getDisplayList(View.java:12775)
    at android.view.View.getDisplayList(View.java:12880)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057)
    at android.view.View.getDisplayList(View.java:12775)
    at android.view.View.getDisplayList(View.java:12880)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057)
    at android.view.View.getDisplayList(View.java:12775)
    at android.view.View.getDisplayList(View.java:12880)
    at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1411)
    at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1359)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2367)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2239)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1872)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
    at android.view.Choreographer.doFrame(Choreographer.java:532)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5103)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)

这是我正在运行的动画:

import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.Transformation;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;

public class DeleteAnim extends AnimationSet {

    public View v;
    int initialHeight;

    public DeleteAnim(View view) {
        super(false);
        v = view;
        initialHeight = view.getMeasuredHeight();

        this.setFillEnabled(true);

        TranslateAnimation anim1 = new TranslateAnimation(0F, 500F, 0F, 0F);
        anim1.setInterpolator(new AccelerateInterpolator(1.5F));
        anim1.setDuration(150);
        anim1.setFillAfter(true);

        this.addAnimation(anim1);


        Animation anim2 = new Animation() {

            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                super.applyTransformation(interpolatedTime, t);

                v.getLayoutParams().height = Math.round(initialHeight * interpolatedTime);
                v.requestLayout();
            }
        };

        anim2.setStartOffset(150);
        anim2.setDuration(350);

        this.setFillAfter(true);

        this.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                DeleteAnim anim = (DeleteAnim) animation;
                ((LinearLayout) anim.v.getParent()).removeView(anim.v);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        if (interpolatedTime == 1) {
            v.setVisibility(View.GONE);
        } else {
            v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
            v.requestLayout();
        }
    }
}

如果有人可以提供帮助,我很想知道这里出了什么问题。另外我只尝试在 API 18 中运行它,一旦动画开始它就会崩溃。

提前致谢!

4

1 回答 1

2

我猜这是因为您在 AnimationEnd 调用中删除了一个视图。坚持一些登录/和或获取Android源并进入。

于 2013-08-27T20:34:43.757 回答