GridView的行删除和动画 - Android电子 [英] GridView row remove and animation - Android
问题描述
我有一个GridView中每一行都有一个自定义视图。网格视图适配器,保持自定义视图的数组。
I have a GridView in which each row has a custom view. The grid view adapter has an array that keeps the custom view.
在点击一个按钮,我想从网格中删除特定行,而这样做,所以我想它的动画。我有一个AnimationListener。
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.
当我从阵列和setAdapter取出最上面的一行onAnimationEnd()。它完美的罚款。但是,当我删除任何其他行,它给在主线程一个NullPointerException异常。
When I remove the upper most row from the array and setAdapter in onAnimationEnd(). It works perfectly fine. But, when I remove any other row, it gives a NullPointerException in the main thread.
下面是code片断:
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)
请帮助!
推荐答案
下面的 android.view.ViewGroup
code。我没有看到你的code,但它看起来当你拔了你空视图返回的行等。
Here's android.view.ViewGroup
code that throws exception. I don't see your code but it looks like when you yank out the row you have null View returned.
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);
}
}
}
这篇关于GridView的行删除和动画 - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!