I use a ViewPager have 3 pages. How to reset MotionLayout and re-run animation when a page is re-selected?
Currently, I call method transitionToStart() when a page replaced by another. But if user swipe back too quickly, animation transitionToStart() won't finish.
Is there a better method?
You can do the following:
motionLayout.setTransition(R.id.transition);
motionLayout.transitionToEnd();
if (instant)
motionLayout.setProgress(1);
You can manually set the progress by calling .setProgress(0) or .setProgress(1)
Based on .setTransition(R.id.transition) you can define start and end constraint (in case you have more than two constraintSets).
Related
I need to create a bottomnavigationmenu that hides like in that one link:
https://github.com/NikolaDespotoski/ahbottomnavigation
But instead of make it fade by scroll, fade with timer, like, 2 seconds of inactivity
Any hints? I don't know how to access the behavior of the scroll through my main activity
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?
During a swipe from View A to View B, when the user releases in the ViewPager
- I would like the ViewPager to freeze at the current point and to animate back, to View A.
How should I implement that?
I have never done that before, but my guess would be to create your own CustomViewPager and make it do the new features for you.
This is the link to the method of the ViewPager that handles which page is to be displayed next.
I would try to add some kind of delay here for your freeze-effect and tweak the float-values which trigger whether you successfully swipe or pop back.
I have implemented one App which has many activities.. . I want to implement one activity as left and right and vice versa in fling transition manner between whole activity. For example
SO when you hit next there should be transition between next activity and when you hit previous there should be transition between previous . How should i Implement this?. ... Its fling but not with touch, but using those buttons...
Check out ViewFlipper (video demo here), ViewPager, or ViewPagerIndicator.
Define translation animations in xml then use overridePendingTransition BEFORE setContentView in each Activity. E.g. overridePendingTransition(R.anim.slidein, R.anim.slideout); You probably need to put this in onResume if you want it to work both ways (i.e. when you're going from and back to that Activity.).
I've used ViewPager to let the user flip left and right to navigate among pages of a given activity.
Is it possible to programatically control the flow of pages of the ViewPager?
For exemple:
If the user didn't fill a given EditText on the current page, I don't want him to be able to navigate to the next one.
Another case: If the user is currently on page 1 and if hi filled a given EditText with a specific value and the user flip right to left, I want him to go straight to the 5th page instead of the 2nd one.
By "flipping" you mean dragging with a finger or just using the ViewPager for animation?
If it's the former, you'll have to dynamically edit the children of the ViewPager to get the effect you want. You can override onInterceptTouchEvent() to block touch events until a page is completed.
However, I recommend disabling finger-dragging in the ViewPager (perhaps using onInterceptTouchEvent()) and then using setCurrentItem(4, true) to show the animation and navigate to a specific page. The logic you need can be implemented using buttons which will call setCurrentItem(4, true). For example, you can have a "Next->" button that is grayed out unless the form is completely completed. That will be more intuitive then the first option anyway.
Edit: 4 is just whatever child index you want to switch to.