Android slow sliding menu when using background images

I use a sliding menu library from https://github.com/jfeinstein10/SlidingMenu It works fine, except for one small thing: when I attach a sliding menu to an activity that has an image as a background, it starts to linger. When I sit right or left, it takes a few seconds for the menu to respond. Has anyone seen this before? Any help would be greatly appreciated.

I am using a png image of about 650 KB in size, but I also tried to use low-quality photos of less than 20 KB, but the problem remained.

My min SDK is 13, the target SDK is 17 (I also tried changing these values, but that didn't help)

This is the layout of one of my actions that uses a sliding menu:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/my_background" android:orientation="vertical" > 

if i remove the android: background value the menu slide is just fine

+4
source share
2 answers

You must add a separate background image for each available folder (drawable-mdpi, drawable-hdpi, drawable-xhdpi, etc.). I tested the presence of only one image in the main accessible folder, it started and closed very slowly and not at all smoothly. If you add background images of different sizes to all available folders, this works like a charm.

+1
source

If someone (like me) still has a problem with the sliding menu and background image, I am trying to explain how I am fixing this problem. @Netis's solution did not help me. As you know, the problem will disappear if you do not use the background in the slide menu, so we need to use something else instead of the standard Android background. For this I use TextureView . In my xml menu, I added:

 <TextureView android:id="@+id/menu_texture_view" android:layout_width="match_parent" android:layout_height="match_parent" /> 

In the activity code when adding the initialization menu:

 final TextureView texture = (TextureView) menuView.findViewById(R.id.menu_texture_view); final Drawable picture = getResources().getDrawable(R.drawable.menu_background); texture.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() { @Override public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { Canvas canvas = texture.lockCanvas(); picture.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); picture.draw(canvas); texture.unlockCanvasAndPost(canvas); } @Override public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { return false; } @Override public void onSurfaceTextureUpdated(SurfaceTexture surface) { } }); 

We basically put our background in a TextureView instead of using standard android paths ( android:background , imageVew , etc.).

Also, as a recommendation, you need to add backgrounds for all dpi (mdpi, hpdi, ...) for better performance.

I know this ugly solution, but it works for me when nothing else helped ...

0
source

Source: https://habr.com/ru/post/1493093/


All Articles