Reputation: 3964
i added rebound animation to all item which is a row of recylerview. But the animation is beginning when the rows is appeared. How can i start animation when the scroll event is stopped?
Any idea?
i am calling below method in the onbindviewholder
like that:
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
//some codes here
setReboundAnimationtoProfilePicture(holder.image5IV);
}
private void setReboundAnimationtoProfilePicture(ImageView imageView){
SpringSystem springSystem;
Spring mScaleSpring;
SpringConfig config;
springSystem = SpringSystem.create();
//config = SpringConfig.defaultConfig;
mScaleSpring = springSystem.createSpring();
Crashlytics.log(Log.ASSERT, "velocity ", mScaleSpring.getVelocity() +"");
Random rand = new Random();
int randomTension = rand.nextInt((40 - 28) + 1) + 28;
int randomFriction = rand.nextInt((25 - 15) + 1) + 15;
//config.tension = 40;
//config.friction = 5;
SpringListener mSpringListener = new SpringListener(imageView);
mScaleSpring.addListener(mSpringListener);
Handler handler = new Handler();
handler.post(new myRunnable(mScaleSpring, handler));
}
Spring Listener
private class SpringListener extends SimpleSpringListener {
private ImageView imageView;
public SpringListener(ImageView imageView){
this.imageView = imageView;
}
@Override
public void onSpringUpdate(Spring spring) {
float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.5);
imageView.setScaleX(mappedValue);
imageView.setScaleY(mappedValue);
}
}
Thanks.
Upvotes: 3
Views: 1025
Reputation: 20626
Maybe you can use onScrollListener() and to soemthing like this :
RecyclerView.setOnScrollListener(new OnScrollListener() {
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
//Is scrolling
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
//Start animation
}
}});
Upvotes: 1