【发布时间】:2015-04-10 08:39:24
【问题描述】:
我知道,我必须在动画之后重新定位实际视图,以使其之后可点击。我找到的解决方案是使用视图的 .layout(l,t,r,b) 方法。
但是现在发生的情况是,视图正确地向上移动了 150 像素,但随后(当调用上述方法时)又向上跳跃了 150 像素。所以我的视图的“hitbox”现在是我期望的位置,但我的视图的渲染图像在它上面。
点击 hitbox,视图开始向下 150px 动画,然后再次跳跃 150px。
这里有两张图片来说明我的问题。第二张图片显示了它在“向上动画”之后的样子。红色矩形显示我希望图像的位置。
之前:
之后:
以下是重要的代码行:
animSlideUpButton = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -150);
animSlideDownButton = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -150, Animation.ABSOLUTE, 0);
animSlideUpButton.setDuration(1000);
animSlideDownButton.setDuration(1000);
animSlideUpButton.setFillAfter(true);
animSlideDownButton.setFillAfter(true);
animSlideUpButton.setAnimationListener(this);
animSlideDownButton.setAnimationListener(this);
听众:
@Override
public void onAnimationEnd(Animation animation) {
if(animation == animSlideUpButton){
int left = containerBttToggleFooter.getLeft();
int top = containerBttToggleFooter.getTop();
int right = containerBttToggleFooter.getRight();
int bottom = containerBttToggleFooter.getBottom();
containerBttToggleFooter.layout(left, top-150, right, bottom-150);
}else if(animation == animSlideDownButton){
int left = containerBttToggleFooter.getLeft();
int top = containerBttToggleFooter.getTop();
int right = containerBttToggleFooter.getRight();
int bottom = containerBttToggleFooter.getBottom();
containerBttToggleFooter.layout(left, top+150, right, bottom+150);
}
}
有什么想法吗?
【问题讨论】: