使用SafeViewFlipper避免ViewFlipper交替时Crash
柳志超博客 » Program » Andriod » 使用SafeViewFlipper避免ViewFlipper交替时Crash
posted in Andriod on 2014/02/19 by liuzc
ViewFilpper 是Android官方提供的一个View容器类,继承于ViewAnimator类,用于实现页面切换。当我们界面重叠较多的时候,ViewFilpper 容易崩溃,直接导致程序Crash。
我们可以使用自定义的SafeViewFlipper来避免这一问题。
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ViewFlipper; public class SafeViewFlipper extends ViewFlipper { public SafeViewFlipper(Context context) {
super(context);
} public SafeViewFlipper(Context context, AttributeSet attrs) {
super(context, attrs);
} @Override
public void onDetachedFromWindow() {
try {
super.onDetachedFromWindow();
}
catch (IllegalArgumentException e) {
// This happens when you're rotating and opening the keyboard that the same time
// Possibly other rotation related scenarios as well
stopFlipping();
}
}
}