I’m trying to create some kind of gallery view for my game’s level select menu. There are three items placed horizontally and two buttons: left and right. When I press the right button those three items should all move to left, and when there’s a left button click – the items move to right. I’ve found a problem using a transform animations android:fillAfter atribute: if it’s true and I click a button for the first time the items move where they must and stay there as expected. But on the second click they start moving from their initial position, means their actual coordinates don’t change after the first transformation. Am I missing something? How can I achieve that goal?
I’m trying to create some kind of gallery view for my game’s level select
Share
android:fillAfterdoesn’t change the attributes of the view. It just means they draw in place once the animation is done, but their physical attributes are the same. Your translate animation probably is animating relative to where they are physically located. Also note, the views aren’t actually in the location that you’ve moved them which means if the user touches them, the touch won’t register. They will register if the user touches where they used to be though.What you need to do in this case is animate them from the location they’re currently viewed at to the location you want them to be.
Possible solution:
From left to right:
From right to left:
In this case, I’m animating from left to right from 0% to 100% relative to the parent. With the
fillAfterenabled, the View will (visibly) stay. After that, I’m animating from right to left from 100% to 0% relative to the parent.