1

I am using AnimationDrawable to show loading. Something like this:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/loader_00000" android:duration="12" />
    <item android:drawable="@drawable/loader_00001" android:duration="12" />
    <item android:drawable="@drawable/loader_00002" android:duration="12" />
    ...
</animation-list>

I am using Fragment. I have this animation in ImageView as src and I am showing it above the content of fragment_layout.

I am running animation like this:

(image_view.drawable as AnimationDrawable).start()

Animation works quite well. But I am loading stuff from a server and populating it to components below animation. I am loading stuff in a background thread. Using CoroutineScope with Dispatchers.IO. However, populating of stuff is causing lagging of my animation. How can I improve it to not lag? Is it possible? Is there a better approach?

ardiien
  • 767
  • 6
  • 26
Matej Košút
  • 590
  • 2
  • 10
  • 27
  • 1
    First of all what you are doing seems normal, BUT: Performance questions are particularly hard to answer, without the whole picture, e.g. the exact images, the code to populate the fragment and the device etc. I recommend that you use the [profiler](https://developer.android.com/studio/profile/android-profiler) to analyse the problem and to see what code makes you break the 16ms barrier. If you want a profound answer to your problem please provide a [mcve](https://stackoverflow.com/help/mcve) – leonardkraemer Apr 18 '19 at 11:47
  • Have you tried to lower the background thread priority? – Michael Butscher Apr 18 '19 at 12:04

0 Answers0