Reputation: 17
Quick note, I'm not the most experienced with the android API and terminology. Sorry if I miss name something. My project is currently using API 17.
I'm working on a project that has a RAL color chart fragment. This fragment has a little over 280 images of the color and the RAL number.
The RAL fragment lags progressively worse as you scroll down. I've set largeHeap to true, but from what I've read you want to avoid doing this unless you have to. I've all compressed all images by almost 50% and this dramatically improved performance. I would compress them more, but it changes the colors slightly and this would make the chart more and more inaccurate than it already is.
The basic layout of the page is three images per row
(Looks kinda like this)
Image1 Image2 Image3
Image4 Image5 Image6
...
Image71 Image72
(The final row only has 2)
All the code for the images are formatted like this:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="5dp">
<ImageView
android:id="@+id/imageView1000"
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="@drawable/ral1000" />
<ImageView
android:id="@+id/imageView1001"
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="@drawable/ral1001" />
<ImageView
android:id="@+id/imageView1002"
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="@drawable/ral1002" />
</LinearLayout>
I understand that the way I made it may be extremely inefficient, but I have been looking into ways to improve it. I've read a few things on Gridview and recylcerview, but I'm having difficulty wrapping my head around them. Could I use the include tag in this?
Thanks, and insight is very much appreciated.
Upvotes: 0
Views: 89
Reputation: 107
An <include>
tag won't help performance in this case as it's likely due to loading all the images into memory at once instead of on demand like RecyclerView
does. You should look into using a RecyclerView
with a GridLayoutManager
to solve this issue.
Another optimization tip would be to use .webp
https://developers.google.com/speed/webp/ format instead of .png
to save a little more space.
Upvotes: 2