I have activity with two tabs. Both tab uses different fragments. When a particular event occur like user click on item, I am opening another fragment in same activity.
I know how to add fragment dynamically and I also know how to animate it.
Here, how I added fragment to frameLayout
in my activity:
transaction.setCustomAnimations(R.animator.object_slide_in_up, R.animator.activity_hold)
transaction.add(R.id.flSellerHome, fragment)
transaction.commit()
Everything works fine in emulator and newer phones. I have tested with emulator with api 25, it works fine now flickering occur, When I am testing it with real device with api 23 it flicker little, so it doesn't affect, after then when I tested it with api 19, it flickers too much.
So my question is any best practise for doing animation.
My third fragment which is dynamically added contains recylerview with around 20 items from local db, and I also done db fatching in background thread.
No loads on main thread. recyclerview is also simple with one Image and three texts.
Image is also loaded using Glide and also I have override function of glide**
any help is appreciated..
To animate the transition between fragments, or to animate the process of showing or hiding a fragment you use the Fragment Manager to create a Fragment Transaction . Within each Fragment Transaction you can specify in and out animations that will be used for show and hide respectively (or both when replace is used).
At a high level, here's how to make a fragment transition with shared elements: Assign a unique transition name to each shared element view. Add shared element views and transition names to the FragmentTransaction . Set a shared element transition animation.
FragmentManager is the class responsible for performing actions on your app's fragments, such as adding, removing, or replacing them, and adding them to the back stack.
I found problem is with recyclerview data updation.
I am loading data in background thread, but when notifying recyclerview, it stucks for small amout of time.
So what I have done is. I have delayed data load for same amount of time which is for animation.
I don't know it is good idea or bad idea. But it is too late for my project so I used this workaround.
I wanted to write comment to your answer, but I dont have enough rep, but I want try to advice you something, so sorry for this.
I am loading data in background thread, but when notifying recyclerview, it stucks for small amout of time.
Try to start loading, which you did, after click and show simple ProgressBar, and when data is loaded, hide progress bar, set info to your fragment and then show fragment. Then you will have all data wich you need in fragment when it is attached and can put it (data) to your adapter.
It have to look good.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With