我希望显示一个在过度滚动而不是默认色调叠加层上动画的项目。
会有一个小动画然后反弹回来。
这是完整的序列:
谢谢!
答案 0 :(得分:0)
我有一个reyclerview适配器,其中包含带动画的footerview。当用户在末尾附近滚动时,我会在页脚视图中启动animatinon,当它完成时我向后滚动reyclerview,使得页脚视图不在屏幕上。
private void configureFooterItemAnimation(RecyclerView itemRecyclerView, LinearLayoutManager linearLayoutManager,
ProductRecyclerAdapter productRecyclerAdapter) {
int productWidth = activity.getResources().getDimensionPixelSize(R.dimen.product_footer_width_plus_15);
itemRecyclerView.addOnScrollListener(new OnScrollListener() {
@Override
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
super.onScrolled(recyclerView, dx, dy);
if (recyclerView.getScrollState() == SCROLL_STATE_IDLE) {
return;
}
if (linearLayoutManager.findLastVisibleItemPosition() == productRecyclerAdapter.getItemCount() -1) {
final LottieAnimationView footerView = productRecyclerAdapter.getFooterView();
if (!footerView.isAnimating()) {
footerView.addAnimatorListener(new AnimatorListener() {
@Override
public void onAnimationStart(final Animator animation) {
itemRecyclerView.setOnTouchListener(getConsumeAllEventsOnTouchListener());
itemRecyclerView.scrollBy(dpToPx(activity, 230), 0);
}
@Override
public void onAnimationEnd(final Animator animation) {
itemRecyclerView.scrollBy(-productWidth, 0);
footerView.removeAllAnimatorListeners();
itemRecyclerView.setOnTouchListener(null);
}
@Override
public void onAnimationCancel(final Animator animation) {
}
@Override
public void onAnimationRepeat(final Animator animation) {
}
});
footerView.playAnimation();
}
}
}
});
}
@NonNull
private OnTouchListener getConsumeAllEventsOnTouchListener() {
return new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
};
}