When I do transaction.setCustomAnimations(R.anim.move_left_in, R.anim.move_left_out), instead of sliding the fragment out: the window first remove the view child views and then slide. This makes for a poor user experience. What I want is for the view and all its children intact to simply slide out. I am using the same transition for activities and it works fines; no funny attenuation before sliding. How might I get the fragment transition to behave more like the activity transition?
MyFragment fragment = new MyFragment();
fragment.setArguments(bundle);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.move_left_in, R.anim.move_left_out);
transaction.replace(R.id.holder, fragment, MyFragment.class.getSimpleName());
transaction.addToBackStack(null);
transaction.commit();
Related
So I saw on an android developer site the example implementation of a ViewPager. I saw that ViewPager must be set in an activity class. My application has only one Actvity with about 15 Fragments. The thing I want to do is to use ViewPager only for 3 Fragments, for example:
I go to Fragment 5
When I click back I go to Fragment 1 (this is yet implemented)
When I swipe in Fragment 5 from left to right I go to Fragment 4
When I swipe in Fragment 5 from right to left I go to Fragment 6
When I swipe in the Fragment4/Fragment6 I go back to Fragment 5
When I swipe in the rest of Fragments, nothing happens
Is this even possible with only one Activity containing these all fragments? I will be grateful for any kind of hints.
PS: If that is gonna be helpful answering my question, this is how I switch between fragments now:
MealInfoFragment fragment = new MealInfoFragment();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.addToBackStack(MainActivity.currentFragment);
fragmentTransaction.commit();
Just for the record, I did it by creating a viewpager in a fragment that contains other 3 fragments!
I have an activity with a fragment container layout and in that layout i load a fragment A which has a listview (listview loads data from web). Now on clicking listview item i want to show detail view. For that i am loading another fragment B which is detail fragment. Now to do that first i used
FragmentTransaction ft = ((FragmentActivity) context).getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragmentsContainerLayout, new ScheduleDetailsFragment());
ft.addToBackStack(null);
ft.commit();
But using replace remove the previous fragment A which contain listview and on pressing back it again reloads the onCreateView method of fragment A and its listview data. I want to prevent it from loading fragment A again (or sending call to webserver) on backpress. I want to maintain fragment A state and its listviews scroll position. To do that i used second option which is
FragmentTransaction ft = ((FragmentActivity) context).getSupportFragmentManager().beginTransaction();
ft.add(R.id.fragmentsContainerLayout, new ScheduleDetailsFragment());
ft.addToBackStack(null);
ft.commit();
If i use add() then Fragment B loads on top of Fragment A and Fragment A still visible. It shows both fragments overlapping each other and transparent. I also came across anothe solution which is to use show() and hide() methods. But i dont think that is an efficient way to achieve that. Can anyone suggest an effective solution?
I have an application with a stack of Fragments added on top of each other.
The Fragments are animated to slide in when opened, and slide out when popped from the backstack. Here's a sample of where I open each Fragment:
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_right,0,0,android.R.anim.slide_out_right);
ft.add(R.id.examplecontainer, examplefragment);
ft.addToBackStack(null);
ft.commitAllowingStateLoss();
The animations work as expected, and everything is good.. except that my App also has a couple more Tabs managed by a FragmentTabHost.
When I switch to another Tab and come back, I want the top Fragment to appear without any animations. Instead, it slides in again.
Is there any way to disable animations when switching between tabs on FragmentTabHost? Or any way to remove/change the custom animations set to a fragment?
Thank you in advance for any hints/suggestions.
I have developed an android application by extending to FragmentActivity. Everything works exactly as it done. I have put NAVIGATION_MODES as TABS. I have a LISTVIEW inside TAB A of FRAGMENT A. When the user clicks on LISTVIEW ITEM, new Fragment/ACTIVITY should launch showing the same ACTION BAR and same TABS. How can I achieve this.
Please suggest any methods.
Thanks
Get the container of the current Fragment A with the ListView and replace the Fragment inside
so in the onclick method of the listview adapter:
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(FragmentA.this.getParent().getID(), mNewFragment);
ft.addToBackStack(null);
ft.commit();
since FragmentA.this.getParent().getID() is very clunky, search for the ID of the Container where FragmentA is located in, and use it instead. R.id.FragmentAContainerID
I have 2 Fragment's - A and B.
In order to switch from Fragment A to Fragment B I'm using this function:
public static void swapFragments(FragmentManager fragmentManager, int containerViewId, Fragment newFragment) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(containerViewId, newFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
Let's say Fragment A takes the entire screen's area and Fragment B takes only the upper half of the screen.
The problem: When switching to Fragment B, the user is still able to see Fragment A at the lower half of the screen...
How can I hide Fragment A when switching to Fragment B ?
p.s: I don't want to use replace instead of add in the swap function above - I don't want Fragment A's onCreate() to be called each time the user navigate back from Fragment B to Fragment A...
Thanks in advance.
Could you maybe move Fragment A? E.g. slide it down when Fragment B appears? Simply move it outside the screen. Something like what's discussed in this question
Well, without any other option, I've just took care that Fragment B will occupy the entire screen so that Fragment A can't be seen.
More adjustments should have n=been done due to Android's bugs, such as: Google's stupid bug