Recyclerview回弹动画

时间:2016-01-14 15:28:26

标签: android animation android-animation android-recyclerview

我将回弹动画添加到所有项目,这是一行recylerview。但是当行出现时动画开始了。如何在滚动事件停止时启动动画?

有什么想法吗?

我在onbindviewholder中调用以下方法:

    @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);
    }
}

感谢。

1 个答案:

答案 0 :(得分:1)

也许你可以使用onScrollListener()并使用这样的东西:

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
       }
}});