I am using fragment and i have setTransition for the fragment. fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
How to increase the speed of the transition for the fragments?
setTransition is for selecting the standard transition animation for the transaction. You can check setCustomAnimations if thats what you need. I have never used that though.
Related
I use a BottomNavigationView for switching between fragments. The problem is that my first view has a webview included which is quite CPU heavy. I implemented a caching mechanism which holds my fragments in the backstack. Whenever i switch to a fragment, my app searches for the fragment and if it is not initialized, it creates a new one. So when i switch from the first to the second fragment or vice versa, my transaction animation is not really shown and it lags a bit.
Do you have any idea how I can make it perform better, or how I can prevent the lag, and make a smooth transition between those fragments?
If you don't care about visual delay, you could postpone the webview's loading with
webview.postDelayed({
//loading goes in here
},200)
I've chosen to hide/show my fragments during navigation for smoother animations.
To display a fragment, I add an animation :
transaction.setCustomAnimations(R.anim.from_right,
R.anim.to_left, R.anim.from_left, R.anim.to_right);
Then I simply hide previous one, show next one.
The problem is if I want to "popback" the fragment, I don't use the normal addToBackStack(null);
Instead I just hide the previous one and show the next one again. But this way the animation is not played. I don't want to save which fragment should use which animation every time.
How do I use the animations I initially set up in setCustomAnimations when I leave the fragment, in the same way a popBackStack would do it?
I am writing an android app that will have a number of different screens that I would like to swipe between, each screen will be a full page except for action bar header. On each screen there is the ability to open up another screen which will also be multiple screens that I would like swipeable. What is the best way to handle this. Do I have one fragment manager that holds all the screens and handle the onPageScrollStateChanged to only allow swipes between the current accessable screens or would I be best off nesting the fragments. I hope the above makes sense.
Thanks in advance
Sounds like you want to use a ViewPager to to swipe between views (Fragment extends View)
You could either:
In a single activity use a FragmentManager that switches between the parent and child Fragments, each with their own ViewPager and nested Fragments
Start a new activity to hold each ViewPager
Both are valid, if the Fragments need to communicate with each other or the Activity option one might suit the project needs better.
For the swiping between views you indeed need a ViewPager
For the nested fragments I would use a wrapper. I struggled a lot with fragments and found that this is the best way. A wrapper is very simple. This is just a fragment that holds other fragments. In the onCreate() of this fragment you get the childFragmentManager and add the fragment you originionally wanted to add. If you want to go to a new fragment you simply get the childFragmentManager again and replace the current item. This way you have nested fragment. You can add this to the backstack in order to get back navigation, but you need to override onBackPressed() inside your activity and call the method popBackStack() from the fragmentManager in order to get the first fragment back.
If you have any questions, comment below.
I have got a viewpager that hosts two Fragments. Now I would like to replace one of the Fragments on a button click. How can I animate this replacement? (e.g. using the flip-card effect)
Since it is difficult two put all my code in here, this is what I basically use
http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html
You can animate it using a PageTransformer
Or, if you want the animation on replacing a fragment, you can set a custom animation on the FragmentTransaction
I'm using the Support Library and replacing a fragment with a custom slide-in animation.
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(enterIn, enterFragmentOut);
transaction.replace(R.id.content_frame, contentFragment);
transaction.commit();
The problem I'm experiencing is that the animation starts concurrently with the drawing of the fragment's views, and since the fragment has a rather complex layout (ListViews, &c) the animation is very stuttery (only a handful of frames are shown).
I've tried splitting the operation into two parts (with transaction1 = {add_new, hide}, transaction2 = {remove_old, show}) and firing the second transaction after onCreateView() has executed on the new fragment, but I didn't get much improvement at all.
What I'm looking for is a way to start the animation after the new fragment is fully drawn, if that's at all possible. Or any other tips that you may have on this issue...
Any ideas? Thanks a lot.