zoukankan      html  css  js  c++  java
  • 使用SafeViewFlipper避免ViewFlipper交替时Crash

    使用SafeViewFlipper避免ViewFlipper交替时Crash

    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();
            }
        }
    }
  • 相关阅读:
    LeetCode 169
    LeetCode 152
    LeetCode 238
    LeetCode 42
    LeetCode 11
    GDB基本调试
    小咪买东西(最大化平均值)
    codeforces 903D
    hdu 5883
    hdu 5874
  • 原文地址:https://www.cnblogs.com/duanweishi/p/4518364.html
Copyright © 2011-2022 走看看