【发布时间】:2011-08-24 14:24:29
【问题描述】:
我有一个可以识别滑动手势(向上和向下)的 FrameLayout。
例如:如果执行向上滑动,我应该为当前视图(即 MATCH_PARENT x MATCH_PARENT)设置动画,以在新视图从底部出现的同时上升。
我可以通过动画实现这一点吗?
【问题讨论】:
我有一个可以识别滑动手势(向上和向下)的 FrameLayout。
例如:如果执行向上滑动,我应该为当前视图(即 MATCH_PARENT x MATCH_PARENT)设置动画,以在新视图从底部出现的同时上升。
我可以通过动画实现这一点吗?
【问题讨论】:
我是这样解决的:
private void swipeUp() {
current.currentPage++;
final View hidingView = currentView;
TranslateAnimation hide = new TranslateAnimation(0, 0, 0, -getHeight());
hide.setAnimationListener(new AnimationListenerAdapter() {
@Override
public void onAnimationEnd(Animation animation) {
hidingView.setVisibility(View.GONE);
}
});
hide.setDuration(1000);
hidingView.startAnimation(hide);
TranslateAnimation show = new TranslateAnimation(0, 0, getHeight(), 0);
show.setFillAfter(true);
show.setDuration(1000);
View nextView = getView();
addView(nextView, createLP());
nextView.startAnimation(show);
currentView = nextView;
}
【讨论】:
如果你想真正切换视图,你需要实现一个处理动画的AnimationListener。如果您想要更复杂的行为,例如视图之间的“手指跟随”滚动条,您可能必须使用更复杂的东西,但如果您只是说
if(I flicked upwards)
move view up
那么 AnimationListener 非常适合您。只需确保在代码中将侦听器设置为 Animation。
希望这会有所帮助!
【讨论】: