I am try to do two animation while navigation from one fragment to other fragment.
When I am in onefragment,On the tab click of activity,current fragment should slide left and on the launch of new fragment it should be sliding from right.
I tried intially using FragmentTransaction's setCustomAnimations(),but it was not successful.
So I am doing animations on status of fragment.So the SlideLeft transititionm,I am doing in Stop() of the fragment,While SlideIn transistion has been done on OnAcitvityCreated() of the fragment.
Please let me know Is this correct way or any other appropriate way to handle this
Related
my problem is when I am going from first fragment to another fragment and come again to
the first fragment motion animation stuck
I have a sliding pane layout with a listview on the left, and a pane with my fragments on the right. When I click the listview items, my fragment correctly loads in the right side pane. The user then needs to slide the pane to bring it to the forefront. I would like the pane to automatically slide to the forefront when the user clicks the listview item, instead of having to manually slide it.
This is where I load my fragment into the side frame. Again, this is working 'correctly', but not with the functionality I am looking for.
fragmentManager.beginTransaction()
.replace(R.id.frame_to_be_replaced, fragment)
.commit();
I think you may be hiding the fragment because the replace and commit methods should immediately show the fragment. Try this for now, FragmentTransaction.show() method.
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 have a ViewPager with a FragmentPageAdapter set for it.
And the ViewPager is show some simple fragment.
I am able to use ViewPager for swipe between fragments.
However, I don't like the scrolling effect of ViewPager that showing partial content of next fragment while swiping/dragging current fragment.
Instead, I would like to switch to next fragment at instant with swipe(but without scrolling effect) and show fragment immediately.
How can I do such thing(must use ViewPagger)?
You have to implement your own "SwipeDetector" and use mViewPager.setCurrentItem(index, false) method (second parameter indicates whether to enable animation or not).
I have a scenario in which from an activity, on the click of a button, I need to show a fragment with sliding in from right to left and similarly when I press back fragment slides back to the right and shows my previous activity from which the fragment was added.
Now my issue is that the animation to the fragment itself works but I need to animate the activity by sliding out to the left while the fragment is sliding in from the right.
Tried using overridePendingTransition method to do this:
overridePendingTransition(R.anim.push_in_from_left, R.anim.push_out_to_left);
I tried putting the pending transition in the methods available with the activity onResume, onPause, etc. but didn't get it to work. Following is the code I am using:
overridePendingTransition(R.anim.push_in_from_left, R.anim.push_out_to_left);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.pull_in_from_left, R.anim.push_out_to_left, R.anim.pull_in_from_left, R.anim.push_out_to_left);
transaction.add(R.id.events_holder, myFragment);
transaction.addToBackStack("myFragment");
transaction.commit();
Tried to put the pending transition on the click of the button as well, before I start doing the fragment transaction things, but didn't work either.
It would be really helpful if anybody can suggest a solution to this problem.
You aren't overriding any animation, sliding in a fragment should not move the layout of the activity if you are doing it right. Instead you have to apply an animation which you can define in an xml to the layout containing your activity. In essence you will give the appearance your activity slides out, and fragment slides in. Depending on what target you are building for, after you apply the animation you may need to actually move (in this case applying an animation doesnt actually change the physical location of the layout, it will simply render where you tell it.) the layout containing the fragment. You dont need to physically move the layout containing the activity, because if you specify an empty onclick listener for the bottom layer layout in the fragment no clicks will fall through. When you are done, use another xml animation file to slide the fragment and Activity layout back the way they were (so an opposite animation) and then physically move the fragment back out of the way, or it will still receive all of the on click events. (I do believe this issue has been fixed if you are targeting a new sdk)
an animation xml looks something like this
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="300"/>
</set>