SlidingMenu icon indicating copy to clipboard operation
SlidingMenu copied to clipboard

View.LAYER_TYPE_HARDWARE cause SurfaceView becomes transparent in 5.0 devices

Open codezjx opened this issue 9 years ago • 1 comments

I faced a problem when content view with SurfaceView becomes transparent while sliding, just appear in 5.0 devices. (Samsung SM-P550 & Moto X Pro)

Finally I see a log output in logcat when issue coming:

V/SlidingMenu: changing layerType. hardware? true

This log output contains in SlidingMenu.java:

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public void manageLayers(float percentOpen) {
        if (Build.VERSION.SDK_INT < 11) return;

        boolean layer = percentOpen > 0.0f && percentOpen < 1.0f;
        final int layerType = layer ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE;

        if (layerType != getContent().getLayerType()) {
            getHandler().post(new Runnable() {
                public void run() {
                    Log.v(TAG, "changing layerType. hardware? " + (layerType == View.LAYER_TYPE_HARDWARE));
                    getContent().setLayerType(layerType, null);
                    getMenu().setLayerType(layerType, null);
                    if (getSecondaryMenu() != null) {
                        getSecondaryMenu().setLayerType(layerType, null);
                    }
                }
            });
        }
    }

When sliding start, this code will call setLayerType(View.LAYER_TYPE_HARDWARE, null), and SurfaceView becomes transparent.

Why this will appear, and how to fix?

codezjx avatar Jan 26 '16 07:01 codezjx

And I find a similar issue here: https://github.com/SimonVT/android-menudrawer/issues/13

codezjx avatar Jan 26 '16 08:01 codezjx