0

I am having a recyclerview inside a relative layout and the app is working fine, the navigation drawer is smooth. But I added an Imageview over the recycler view so that I can hide and show based on the availability of the data. But soon as I have added the Imageview the navigation drawer becomes very slow. And when I remove the Imageview it again works smooth. The image size is just 38kb. Can someone tell me how to show empty state in an efficient way

This is my Layout with the ImageView

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.test.sample.itemHistory"
tools:showIn="@layout/app_bar_item_history"
android:background="#ffffff">

<android.support.v7.widget.RecyclerView
    android:id="@+id/materialList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/imageViewNoItems"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/noItems" />
</RelativeLayout>

Thanks in Advance

Amalan Dhananjayan
  • 2,277
  • 1
  • 34
  • 47
  • Possible duplicate of [android background image slows down app](http://stackoverflow.com/questions/14269186/android-background-image-slows-down-app) – Hitesh Sahu Jul 05 '16 at 05:52

2 Answers2

1

In my case, I try to load Image (PNG File within the Project Drawable Resource Folder) to my RecycleView's ImageView as well using Picasso and I facing the same problem where the Navigation Drawer sliding animation is being slow down.

I found that the main issue is because my Image File is quite Large so the Picasso load the Full Size image into the RecycleView's ImageView which would cause the Lag.

My Solution are: (I am using KOTLIN Language)

  1. Re-size the image using Picasso built in resize function

Without Resize (Which Cause Lag):

Picasso.get().load(R.drawable.icon).into(holder.view.ImageView)

Resized (Solve Lag Problem):

Picasso.get().load(R.drawable.icon).resize(400,400).centerCrop().into(holder.view.ImageView)
  1. Use setImageDrawable instead of Picasso

This Method does not required to Resize the image:

holder.view.ImageView.setImageDrawable(holder.view.ImageView.context.resources.getDrawable(R.drawable.icon))
I am a Student
  • 1,570
  • 4
  • 21
  • 36
0

used picasso or glide library for image loading.. and also add one line in your manifest and your project become smooth as before.

    <application
       android:largeHeap="true">
    </application>

largeHeap is used to avoid outofmemory exception while loading images.

Sagar Chavada
  • 5,169
  • 7
  • 40
  • 67