Search code examples
androidandroid-image

Activity containing image button take too much time to load


enter image description here

I have an Activity that has 50+ image button. Each image is about 30-40 kb. When i open the Acitivity it takes 2-3 second. What can i do to open it fast.

   <Button
                        android:id="@+id/desi_unique"
                        android:layout_width="match_parent"
                        android:layout_height="70dp"
                        android:layout_margin="5dp"
                        android:background="@drawable/unique"
                        android:gravity="bottom|right"
                        android:paddingBottom="10dp"
                        android:paddingRight="5dp"
                        android:text="@string/unique"
                        android:textColor="@color/black"
                        android:textSize="15sp" />

Solution

  • Simple answer: CACHING those images.

    If you are gonna use Drawables, try COMPRESSING THOSE IMAGES.

    How?

    Use a library named Glide, by Google.inc. It will automatically cache images for you. Of course, whenever you'll first load the activity, it will take some time, but once it's cached inside your memory, it won't take much time if you'll launch the activity next time.

    Disclaimer: The above statement's scope is limited to a single launch of your application. Once you'll kill your application, you'll have to load them again.

    BUT, loading so many images(from drawables) is not considered as a good practice, it hits the performance of your application by many folds. Thus you should change your UI.

    But again, Recycler View sounds a better option when loading/displaying so many images.