android 探探卡片,仿探探首页卡片式滑动效果

Introduction

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

Screenshot

ec6e1d0ebc0173607baf75b8cd3f834d.gif

Usage

step 1

For build.gradle : compile 'me.yuqirong:cardswipelayout:1.0.0'复制代码

Or Maven :

me.yuqirong

cardswipelayout

1.0.0

pom

复制代码

step 2

init RecyclerView firstly : RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);

recyclerView.setAdapter(...);复制代码

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

recyclerView.setLayoutManager(cardLayoutManager);

touchHelper.attachToRecyclerView(recyclerView);

cardCallback.setOnSwipedListener(new OnSwipeListener() {

@Override

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

*/

}

@Override

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

*/

}

@Override

public void onSwipedClear() {

/**

* will callback when all cards swiped clear

* you can load more data

*/

}

});复制代码

Finally , enjoy it !!!

If you have any questions , you can leave a message in Issues.

Contact Me

License MIT License

Copyright (c) 2017 yuqirong

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files (the "Software"), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all

copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

SOFTWARE.复制代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值