简体   繁体   English

GridView行删除和动画 - Android

[英]GridView row remove and animation - Android

I have a GridView in which each row has a custom view. 我有一个GridView,其中每一行都有一个自定义视图。 The grid view adapter has an array that keeps the custom view. 网格视图适配器有一个保持自定义视图的数组。

At click of a button, I want to remove a specific row from the Grid and while doing so I want animation on it. 单击一个按钮,我想从网格中删除一个特定的行,同时这样做我想要动画。 I have an AnimationListener. 我有一个AnimationListener。

When I remove the upper most row from the array and setAdapter in onAnimationEnd(). 当我从数组中删除最上面的行,并在onAnimationEnd()中删除setAdapter。 It works perfectly fine. 它工作得很好。 But, when I remove any other row, it gives a NullPointerException in the main thread. 但是,当我删除任何其他行时,它在主线程中给出NullPointerException。

Here is the code snippet: 这是代码片段:

Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.pushout);
anim.setAnimationListener(animListener);

public void removeRow() {

final CustomRowView customRowView = rowArray.get(clickedId);
customRowView.startAnimation(anim);

//Remove the row clicked
rowArray.remove(clickedId);
}

private AnimationListener animListener = new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {}

        @Override
        public void onAnimationRepeat(Animation animation) {}

        @Override
        public void onAnimationEnd(Animation animation) {
            gameGrid.setAdapter(adapter);
    }
}

The exception thread is as follows: 异常线程如下:

ERROR/AndroidRuntime(11503): java.lang.NullPointerException
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1227)
at android.widget.AbsListView.dispatchDraw(AbsListView.java:1319)
at android.view.View.draw(View.java:5944)
at android.widget.AbsListView.draw(AbsListView.java:2121)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
at android.view.View.draw(View.java:5841)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1847)
at android.view.ViewRoot.draw(ViewRoot.java:1217)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1030)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1482)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3948)
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:782)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
at dalvik.system.NativeStart.main(Native Method)

Please help!!! 请帮忙!!!

Here's android.view.ViewGroup code that throws exception. 这是抛出异常的android.view.ViewGroup代码。 I don't see your code but it looks like when you yank out the row you have null View returned. 我没有看到你的代码,但看起来当你把你的行拉出来时,你看到的是null。

    if ((flags & FLAG_USE_CHILD_DRAWING_ORDER) == 0) {
        for (int i = 0; i < count; i++) {
            final View child = children[i];
/* line 1227 throws NullPointerException */ if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null) {
                more |= drawChild(canvas, child, drawingTime);
            }
        }
    } else {
        for (int i = 0; i < count; i++) {
            final View child = children[getChildDrawingOrder(count, i)];
            if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null) {
                more |= drawChild(canvas, child, drawingTime);
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM