我正在使用TranslateAnimation在顶部底部的另一个视图上显示片段。问题是在动画结束之前隐藏了后视图,我需要看到视图直到动画结束。
这是我的代码:
buttonLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hideFragment();
}
});
WatchDetails.fourthLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (WatchDetails.showFrag == false) {
showFragment();
}
}
});
public void showFragment() {
System.out.println("showFragment");
mAnimation = new TranslateAnimation(0, 0, 800, 0);
mAnimation.setDuration(500);
mAnimation.setFillAfter(true);
mAnimation.setRepeatCount(0);
mAnimation.setZAdjustment(-1);
mAnimation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
}
});
WatchDetails.frag.startAnimation(mAnimation);
firstLayout.setVisibility(View.GONE);
WatchDetails.frag.setVisibility(View.VISIBLE);
WatchDetails.showFrag = true;
}
public void hideFragment() {
System.out.println("hideFragment");
mAnimation = new TranslateAnimation(0, 0, 0, 720);
mAnimation.setDuration(500);
mAnimation.setFillBefore(true);
mAnimation.setRepeatCount(0);
firstLayout.setVisibility(View.VISIBLE);
secondLayout.setVisibility(View.VISIBLE);
thirdLayout.setVisibility(View.VISIBLE);
fifthLayout.setVisibility(View.VISIBLE);
WatchDetails.frag.startAnimation(mAnimation);
getView().setVisibility(View.GONE);
origButtonLayout.setVisibility(View.VISIBLE);
WatchDetails.showFrag = false;
}