GithubHelp home page GithubHelp logo

jakewoki / recyclerviewitemanimation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zhan2046/viewholder-slide-helper

0.0 1.0 0.0 439 KB

RecyclerView Item Animation 添加动态位移,静态位移,缩放等动画,保证了动画状态的平滑衔接

Java 100.00%

recyclerviewitemanimation's Introduction

####效果如图:


我的博客:详解

RecyclerView Item Animation --- 为Item添加动态位移,静态位移,缩放等动画,保证了动画状态的平滑衔接。


RecyclerView,ListView这些具有Item复用性的View,想要对其Item做动画,需要注意以下几点:

1,如果要一点击,让所有Item做动画的效果。例如,上图的编辑和取消,这样的动态动画。

可以对所有ViewHolder中的View直接做动画。但是需要在onBindViewHolder方法中对复用的item做静态动画,保证动画状态的平滑衔接。

2,处理每一个Item的特有属性,例如,上图checkbox的选中状态,都需要把状态字段放到对应的Java bean中, 并在onBindViewHolder方法从java bean取出状态值,设置到view里。


部分参考代码:

	//对所有ViewHolder中的View直接做动画
    public static final int NORMAL = 1000;
    public static final int SLIDE = 2000;
    private int mState = NORMAL;
	private List<SlideViewHolder> mSlideViewHolders = new ArrayList<>();

	public void openItemAnimation() {
       mState = SLIDE;
       for (SlideViewHolder holder : mSlideViewHolders) {
           holder.openItemAnimation();
       }
    }

    public void closeItemAnimation() {
        mState = NORMAL;
        for (SlideViewHolder holder : mSlideViewHolders) {
            holder.closeItemAnimation();
        }
    }



	//需要在onBindViewHolder方法中对复用的item做静态动画,保证动画状态的平滑衔接
    public void bind(ItemBean itemBean) {
   	    mItemBean = itemBean;

       //在onBindViewHolder方法从java bean取出状态值,设置到view里
        mCheckBox.setChecked(itemBean.isChecked());

        switch (mState) {
          case NORMAL:
             mSlideRelativeLayout.close();
             break;

          case SLIDE:
             mSlideRelativeLayout.open();
             break;
    }
     }

recyclerviewitemanimation's People

Watchers

Jake Woki avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.