Android 获取平移动画后图像的绝对位置
我有一个形象。点击一个按钮,图像上就会出现一个平移动画,这样它就会向左滑动,最后你只能看到一定比例的图像 有没有一种方法可以在平移动画发生后获得图像的位置?我意识到我可以使用动画监听器,并在OnAnimationEnd方法中执行一些操作。然而,我不知道在这里该做什么 如何获取图像移动到的位置并将其设置为图像的布局参数Android 获取平移动画后图像的绝对位置,android,android-animation,Android,Android Animation,我有一个形象。点击一个按钮,图像上就会出现一个平移动画,这样它就会向左滑动,最后你只能看到一定比例的图像 有没有一种方法可以在平移动画发生后获得图像的位置?我意识到我可以使用动画监听器,并在OnAnimationEnd方法中执行一些操作。然而,我不知道在这里该做什么 如何获取图像移动到的位置并将其设置为图像的布局参数 我真的需要你的帮助 假设您当前的图像位置是x,y。你在x方向移动100,y方向移动50。所以你现在的位置是newx=x+100,newy=y+50。您将使用布局在onAnimati
我真的需要你的帮助 假设您当前的图像位置是x,y。你在x方向移动100,y方向移动50。所以你现在的位置是newx=x+100,newy=y+50。您将使用布局在onAnimationEnd方法中放置图像
TranslateAnimation TAnimation=new TranslateAnimation(0, 100, 0, 50)
TAnimation.setDuration(2000);
TAnimation.setFillAfter(true);
Image.startAnimation(TAnimation);
TAnimation.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
RelativeLayout RL=(RelativeLayout)findViewById(R.id.rl);
param=new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
param.setMargins(x+100, y+50, 0, 0);
Image.setLayoutParams(param);
}
});
我知道这个问题由来已久,但它可能会帮助一些人。 您只需添加:
animation.setFillAfter(true);
或在Xml集合中:
fillAfter = "true"
就这样。它将强制视图处于新位置