我正在尝试为我的游戏的关卡选择菜单创建某种图库视图。水平放置三个项目和两个按钮:左和右。当我按下右侧按钮时,这三个项目应全部移至左侧,而当单击左侧按钮时,项目将移至右侧。我在使用变换动画 android:fillAfter
属性时发现了一个问题:如果它是 true
并且我第一次单击按钮,则项目会移动到它们必须移动的位置并停留在那里正如预期的那样。但在第二次单击时,它们开始从初始位置移动,这意味着它们的实际坐标在第一次转换后不会改变。我错过了什么吗?我怎样才能实现这个目标?
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?
发布评论
评论(1)
android:fillAfter
不会更改视图的属性。这只是意味着它们在动画完成后就绘制到位,但它们的物理属性是相同的。您的翻译动画可能是相对于它们的物理位置进行动画处理的。另请注意,视图实际上并不位于您移动它们的位置,这意味着如果用户触摸它们,触摸将不会注册。如果用户触摸他们曾经所在的位置,他们就会注册。在这种情况下,您需要做的是将它们从当前查看的位置动画到您想要的位置。
可能的解决方案:
从左到右:
从右到左:
在这种情况下,我从左到右相对于父级从 0% 到 100% 进行动画处理。启用
fillAfter
后,视图将(明显)保留。之后,我从右向左设置相对于父级的动画,从 100% 到 0%。android:fillAfter
doesn'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
fillAfter
enabled, the View will (visibly) stay. After that, I'm animating from right to left from 100% to 0% relative to the parent.