对RecyclerView Item做动画 源码

[复制链接]
来自: BlueManlove 分类: Android精品源码 上传时间: 2017-11-15 10:31:08
Tag:

项目介绍:

[i=s] 本帖最后由 BlueManlove 于 2017-11-15 10:32 编辑 [/i]

对RecyclerView Item做动画
http://www.apkbus.com/blog-822717-76496.html

Gradle

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency:

dependencies {
        compile 'com.github.ruzhan123:ViewHolder-Slide-Helper:v1.3'
}

Usage

1, recyclerview adapter create ISlideHelper

public class SlideAdapter extends RecyclerView.Adapter {

private ISlideHelper mISlideHelper = new ISlideHelper();

2, use ISlideHelper add holder

@Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

OneSlideViewHolder oneSlideViewHolder = new OneSlideViewHolder(
    LayoutInflater.from(parent.getContext()).inflate(R.layout.one_item, parent, false));

//add holder
mISlideHelper.add(oneSlideViewHolder);

return oneSlideViewHolder;
}

3, extends SlideViewHolder, in onBindViewHolder call holder onBindSlide method

@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
((SlideViewHolder) holder).bind();
}

public class OneSlideViewHolder extends SlideViewHolder {

public void bind() {
//slide offset
setOffset(50);

//slide must call,param is slide view
onBindSlide(mContentRl);
}
}

expend

add animation set, if you holder need

@Override public void doAnimationSet(int offset, float fraction) {
mContentRl.scrollTo(offset, 0);

itemTv.setScaleX(fraction);
itemTv.setScaleY(fraction);
itemTv.setAlpha(fraction * 255);

titleLl.scrollTo(offset, 0);
}

//static bind anmation state
@Override public void onBindSlideClose(int state) {
titleLl.scrollTo(0, 0);
}

//static bind anmation state
@Override public void doAnimationSetOpen(int state) {
titleLl.scrollTo(-mOffset, 0);
}

相关源码推荐:

我来说两句
所有评论(16)
转角依然笑~ 2017-11-15 10:36:35
感谢分享,安卓巴士有你更精彩:lol
回复
九酒 2017-11-15 10:43:05
感谢分享,楼主V5~
回复
myself2015 2017-11-15 10:46:55
每次我都积极回帖的,想要安币~
回复
subsoil 2017-11-15 10:47:15
帮帮顶顶!!
回复
深思 2017-11-15 10:47:55
感觉楼主很用心,辛苦啦~
回复
葫芦_eRDJw 2017-11-15 10:52:35
楼主是好人,回个帖会有安币吗?
回复
apkbus热心网友 2017-11-15 11:05:16
楼主用心了,内容非常精彩。
回复
123下一页
提取码:  下载次数:9 状态:已购或VIP 售价:20(原价:20)金钱 下载权限:初级码农 
2588 0 9
代码贡献英雄榜
用户名 下载数
联系我们
首页/微信公众账号投稿
帖子代码编辑/版权问题
QQ:435399051,1294855032
如何获得代码达人称号?
如何成为签约作者?
领先的中文移动开发者社区
18620764416
7*24全天服务
意见反馈:1294855032@qq.com

扫一扫关注我们

Powered by Discuz! X3.2© 2001-2019 Comsenz Inc.( 粤ICP备15117877号 )