Android中利用TranslateAnimation移动时,不设置mTranslateAnimation.setFillAfter(true);
,而利用视图的setLayoutParams来重新定位。。。。因为mTranslateAnimation.setFillAfter(true);
之后,视图的事件消失,并且还有很多其他的问题。
而我们采用Animation.AnimationListener,在onAnimationEnd的方法中改变当前视图利用LayoutParams的setMargins方法重新定位位置。
代码段,仅供参考。
public void move() {
jqkjScroll.setEnabled(true);
Animation mTranslateAnimation = new TranslateAnimation(0, 0, 0,
-showheight);
// 移动mTranslateAnimation.setDuration(minute);
// mAnimationSet.setFillAfter(true);
// mTranslateAnimation.setFillAfter(true);
mTranslateAnimation
.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
if (isNoMenu == false) {
curent.setVisibility(View.GONE);
}
}public void onAnimationEnd(Animation animation) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
contentLayout.getLayoutParams());
contentImg.setImageResource(R.drawable.open);
params.setMargins(0, endY - startY, 0, 0);
contentLayout.clearAnimation();
contentLayout.setLayoutParams(params);
jqkjScroll.scrollTo(0, 0);
isMoveORShowing = false;
}public void onAnimationRepeat(Animation animation) {}
});
contentLayout.startAnimation(mTranslateAnimation);
} public void show() {
jqkjScroll.setEnabled(false);
Animation mTranslateAnimation = new TranslateAnimation(0, 0, 0,
showheight);
// 移动
mTranslateAnimation.setDuration(minute);
mTranslateAnimation
.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
if (isNoMenu == false) {
curent.setVisibility(View.VISIBLE);
}
}public void onAnimationEnd(Animation animation) {
contentImg.setImageResource(R.drawable.close);
isMoveORShowing = false;
contentLayout.clearAnimation();
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
contentLayout.getLayoutParams());
params.setMargins(0, showheight + endY - startY, 0, 0);
contentLayout.setLayoutParams(params);
}public void onAnimationRepeat(Animation animation) {}
});
contentLayout.startAnimation(mTranslateAnimation);
}
【Android|Android应用TranslateAnimation移动之后,利用视图的setLayoutParams从新定位】