/ Cards

Use RecyclerView to achieve card swipe layout

Use RecyclerView to achieve card swipe layout


CardSwipeLayout - Use RecyclerView to achieve card swipe layout , like Tantan .



step 1

For build.gradle :

compile 'me.yuqirong:cardswipelayout:1.0.0'

Or Maven :


step 2

init RecyclerView firstly :

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);

step 3

then set CardLayoutManager for RecyclerView and CardItemTouchHelperCallback for ItemTouchHelper . In addition , don't forget set OnSwipeListener for CardItemTouchHelperCallback :

// dataList means dataSource for adapter
CardItemTouchHelperCallback cardCallback = new CardItemTouchHelperCallback(recyclerView.getAdapter(), dataList);
ItemTouchHelper touchHelper = new ItemTouchHelper(cardCallback); CardLayoutManager cardLayoutManager = new CardLayoutManager(recyclerView, touchHelper);
cardCallback.setOnSwipedListener(new OnSwipeListener<T>() {

    public void onSwiping(RecyclerView.ViewHolder viewHolder, float ratio, int direction) {
         * will callback when the card are swiping by user
         * viewHolder : thee viewHolder of swiping card
         * ratio : the ratio of swiping , you can add some animation by the ratio
         * direction : CardConfig.SWIPING_LEFT means swiping from left;CardConfig.SWIPING_RIGHT means swiping from right
         *             CardConfig.SWIPING_NONE means not left nor right

    public void onSwiped(RecyclerView.ViewHolder viewHolder, T t, int direction) {
	     *  will callback when the card swiped from screen by user
	     *  you can also clean animation from the itemview of viewHolder in this method
	     *  viewHolder : the viewHolder of swiped cards
	     *  t : the data of swiped cards from dataList
	     *  direction : CardConfig.SWIPED_LEFT means swiped from left;CardConfig.SWIPED_RIGHT means swiped from right

    public void onSwipedClear() {
         *  will callback when all cards swiped clear
         *  you can load more data 


Finally , enjoy it !!!