Manikandan
Manikandan

Reputation: 894

Android backgroud image slow the app

I m using DrawerLayout for left slide menu. My app is getting slow when I use image for background. On the other hand it smooth when I m using color for background.

my code is

<android.support.v4.widget.DrawerLayout    
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:background="@drawable/app_bg"
android:layout_height="match_parent" >

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp" />

</android.support.v4.widget.DrawerLayout>

Here my background image is @drawable/app_bg I don't know how to overcome this and achieve smooth slide move.

My background image .

enter image description here

Upvotes: 0

Views: 6540

Answers (2)

PedroAGSantos
PedroAGSantos

Reputation: 2346

You should have diferente sizes for deferent displays. Multi screen support please take a look at this Android: Background Image Size (in Pixel) which Support All Devices

Upvotes: 2

An SO User
An SO User

Reputation: 24998

If your image is causing your app to slow down, what you can try is to use a <gradient> as a background. Create a gradient in your drawables folder and set it as a background for your FrameLayout

Alternatively,

You can add an ImageView to your FrameLayout as the bottom-most view and add the image to it. Set the width and height to match_parent and the crop type to center. Hopefully, that will do the trick.

Also,

I hope you have the same image for different densities. Same name but different sizes and in appropriate drawable folders.

Upvotes: 1

Related Questions