【发布时间】:2015-04-04 21:05:22
【问题描述】:
我有这样的看法:
ListView 在整个屏幕上,并且按钮始终可见(在 FrameLayout 上)。当用户滚动列表并且他到达终点时,我想用动画将按钮隐藏在屏幕外(在它下方)(动画必须在他到达终点之前开始,这样它才能很好地移出屏幕)。如何实现?
编辑
感谢 PPartisan,我创建了简单的 onScroll 方法,效果很好:
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
final int lastItem = firstVisibleItem + visibleItemCount;
if(lastItem == totalItemCount & button.getVisibility() == View.VISIBLE & hideAnimStarted == false) {
hideAnimStarted = true;
ObjectAnimator animator = ObjectAnimator.ofFloat(button, View.TRANSLATION_Y, 100);
animator.setDuration(300);
animator.start();
animator.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) { }
@Override
public void onAnimationRepeat(Animator animation) { }
@Override
public void onAnimationEnd(Animator animation) {
button.setVisibility(View.GONE);
}
@Override
public void onAnimationCancel(Animator animation) {}
});
}
else if(lastItem < totalItemCount & button.getVisibility() == View.GONE){
button.setVisibility(View.VISIBLE);
hideAnimStarted = false;
ObjectAnimator animator = ObjectAnimator.ofFloat(button, View.TRANSLATION_Y, 0);
animator.setDuration(300);
animator.start();
}
}
【问题讨论】:
标签: android android-listview android-scroll