我有2个ImageView
我从屏幕顶部翻译到底部。这些视图是从 xml 中获取的,动画是从 java 代码中添加的。动画效果很完美,但是onClickListener
我在java代码中添加似乎不起作用。我用了fillAfter
动画的属性,使图像在翻译后保持在到达位置,但这些图像不再可单击...但是,它们在翻译前的位置仍然可单击...
我看不出这其中的逻辑。有人能给我一些建议吗?
这是因为动画仅影响小部件的绘制。然而,真实的位置不受影响——它仍然在前一个位置——。
为了解决这个问题,您需要通过安装动画监听器来手动更新 ImageView 的布局参数,如下所示:
Animation.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation arg0) {
}
public void onAnimationRepeat(Animation arg0) {
//TODO Auto-generated method stub
}
public void onAnimationEnd(Animation arg0) {
android.widget.LinearLayout.LayoutParams params = new LayoutParams(
android.widget.LinearLayout.LayoutParams.FILL_PARENT,
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
params.topMargin = addLocationButton.getTop()-100;
ImageView.setLayoutParams(params);
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)