I have a fragment manager, and I am using custom animations with it. But the idea is that the user can swipe a fragment away, and I need a way to change the exit animation based on the user swipe. Is there a way I can setCustomAnimations on an already committed transaction?
Related
I'm trying to do a sort of infinite scroll. Each Fragment contains a scrolling WebView (or ScrollView), and when the user hits the bottom, I'd like to test for continued swiping to reveal the next Fragment below.
The user should not be able to go back, and I'm not interested in caching, so that rules out RecyclerView or ViewPager (modified to scroll vertically). I'm only concerned about managing the current Fragment, loading the next, and removing the last one once it's offscreen.
I want the next Fragment to follow the users touch, and I want the transition to abort if the user lets go below a certain threshold.
FragmentManager allows custom animations but they are non-interactive. I could perhaps write my own ViewGroup where I can manually animate a Fragment into position, and remove the previous Fragment manually, but I'm not sure if this is the best path forward.
Anyone have thoughts/tips on a good approach here?
I want to create application which structure can be simplified as this:
Where Events tab has static content in our stackoverflow world, and is not reloading when app is working. So we can simplify it as a ViewPager.
Problem is with reloading Home tab, because when we set option in Drawer, accurate fragment should replaced Home tab.
Question
So here is my question, is it something similiar to ViewPager which replace current window from right side ? Because I replacing fragment in view pager is quit hard, so I want to replace home fragment in traditional way.
I`m not sure what your problem is. You don't want to update home fragment, you just want to replace it, so replace it and notify viewpager adapter for your change, save preview fragment before that and override back button press logic to replace again whit backuped fragment.
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 want to swipe between fragments, and I am currently using the viewpager.
There is one problem though: When I swipe to the right, entries made in EditTexts of the current
fragment need to be validated, and only if the input is ok, it should be swiped to the next page.
I managed to do that by disabling the viewpager when necessary, however then I also cannot swipe to the left (i.e. the previous fragment), since the method to validate the input (onPageScrolled(...)) is not called anymore due to the fact that the viewpager is disabled. It is only enabled again when I type something in the EditText.
I haven't found a way to deal with that problem yet.
So I'd like to know if there is an alternative to using fragments with swipe gestures? Maybe in combination with the viewpager's setCurrentItem() method, but without using the viewpagers scrolling-animation?
Problem: Upon clicking a button in a fragment inside of the ViewPager the click falls through to the fragment that is behind it and registers the onClickListener() in the behind fragment rather than the current fragment’s onClickListener().
Situation: I have a ViewPager with 4 fragments in it. Each fragment contains a few rows of custom made buttons. Each fragment has it’s own unique view/layout, yet they are all designed similarly.
Set Up: I am using the FragmentPagerAdapter, because I have a short list of pretty static fragments AND because I need to communicate and update each fragment by using an interface, like how the developer docs suggest.
My Idea: Should I switch to the FragmentStatePagerAdapter? So the adapter will destroy the fragments when they are not visible? But in doing this, will I not be able to communicate with the fragments and update them accordingly?
I don’t know how to solve this problem and it has been driving me mad! Any help is appreciated.
Ask me if I need to clarify anything.
The reason that the fragment behind/after/to-the-right of the current fragment in the viewpager was catching the button clicks was because of the use of the PageTransformer class that I used to add a fade out animation to the pages upon sliding. This PageTransformer animation messed everything up on android version 4.1.1 API 16 and version 4.2.2 API 17. SO be weary of using PageTransformer, especially if you want to support older android versions.