0

i have a simple animated fragment transition in login section of my app - see anim.xml . Fragments have background set from drawables in xml and everything works just fine unless I test it on my smartphone with full hd display. Transition suddenly becomes laggy. Anyone knows what could be causing this ? Both backgrounds have 1080*1920 resolution.

anim.xml - example of animation (have 4 of them for in and out animation from both sides)

<?xml version="1.0" encoding="utf-8"?>
<set>
  <translate xmlns:android="http://schemas.android.com/apk/res/android"
   android:fromXDelta="-100%"
   android:toXDelta="0"
   android:interpolator="@android:anim/decelerate_interpolator"
   android:duration="250"/>
</set>
TheJudge
  • 576
  • 1
  • 9
  • 30

3 Answers3

4

Few years of experience later - put your image in drawable-nodpi

nodpi

These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density.

What Is The Difference Between -anydpi And -nodpi?

TheJudge
  • 576
  • 1
  • 9
  • 30
2

To me it seems you have a performance problem (probably with GPU, maybe you have an overdraw). I don't know what is the cause of it but there is plenty of tools that might help you better understand what's happening. Take a look at this article http://www.curious-creature.com/docs/android-performance-case-study-1.html

Also android performance patterns videos might be helpful. I strongly suggest watching these:

Tool - Profile GPU Rendering https://www.youtube.com/watch?v=VzYkVL1n4M8

Overdraw https://www.youtube.com/watch?v=T52v50r-JfE

UI and GPU https://www.youtube.com/watch?v=WH9AFhgwmDw

Why 60 ms https://www.youtube.com/watch?v=CaMTIgxCSqU

bryn
  • 291
  • 1
  • 3
  • 5
1

Well, after some time (long time) trying to solve this, the only solution to my problem was to change background image just before the Fragment transaction to some low res image and check the end of animation to change it back to high res image. Ugly but at least it works.

Though if you go this way in future, expect some troubles with detecting end of animation. Fragments have onCreateAnimation method where you can add AnimationListener which has methods to detect start, repeat and end of anims but it has buggy behaviour detecting end of animation. The callback is fired just before the animation ends which makes your fragment transaction laggy just as its about to end (in my case it was last ten pixels or so).

Solved it in a very ugly way - implemented a CountDownTimer for 10ms at the end of animation and changed background to high res after timer ended.

Also, Fragment's onCreateAnimation has minimal documentation so you'll have no idea what its parameters are, i found this Asian webpage which helped me understand it.
http://y-anz-m.blogspot.cz/2013/05/support-package-fragmenttransaction.html

Anyway, I dont know how the background of FragmentTransaction works but thank you Google for such great implementation of both FragmentTransactions and AnimationListeners.

TheJudge
  • 576
  • 1
  • 9
  • 30