Issue
I want to make a dashboard, where you can swipe up to reveal a second section that isn't visible yet. I already know how to detect user input (when the screen is swiped), but I don't know what animation would be the best one for this specifically. I don't need code, just some insight on approaches and the best animation type for the job as I'm new to android dev
There's a question similar to this, but the answer only includes resources on user input (which I don't need)
Solution
If you're a beginner, I believe trying to implement this is a really good exercise for you. Based on your example, I see you have 2 views overlaye A|B, where A is the black arrows overlay and B is the green background.
Now, given you said you already know how to intercept the touch events, then I suggest to simply translate the the A view vertically, to reveal b.
- while the user is dragging, make sure you accumulate and apply the drag to A.
A.translationY = accumulatedDrag
- decide a threshold which should trigger either a full reveal, or a cover animation once the user lifts his finger:
if (accumulatedDrag > revealThreshold) {
animateToFinalPosition(-A.height)
} else {
animateToFinalPosition(0)
}
What this does is:
- if the drag passed the threshold, you should animate the view out of the screen. That means, the accumulatedDrag needs to reach the negative height of the view (swipe up)
- If the drag hasn't reached the threshold, you should snap back the view to it's starting point, which means you should have an accumulatedDrag of 0 at the end of the animation.
Answered By - Cristian Holdunu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.