这不是一个问题,更像是与他人分享我遇到的问题以及我是如何解决的.
基本上,我正在尝试创建一个ViewAnimator,他会根据用户点击创建额外的子项.
在我动画下一个View之后进行清理,我把它放了
outAnimation.setAnimationListener(listener);
并在AnimationListener中
public void onAnimationEnd(Animation animation) {
viewAnimator.removeView(out);
}
现在,上面方法的问题是,在onAnimationEnd之后,它会抛出NullPointerException.基本上,这意味着,ViewAnimator仍在使用正在动画绘制的子视图.因为我删除了它,那里有空.
我做了我的研究,基本上,这似乎是一个已知的错误.见:Android Animation is not finished on onAnimationEnd
?
为了解决这个问题,我修改了布局.
android:id="@+id/animator"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:id="@+id/container1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:id="@+id/container2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
和onAnimationEnd我可以安全地调用container.removeAllViews().要为新视图设置动画,我选择隐藏的容器和
container.addView(newView);
animator.setDisplayedChild(animator.indexOfChild(container));
我很乐意看到您的意见和建议.