仿微信消息列表(RecycleView)双击移动未读消息

/**
* 仿微信双击移动未读消息
*/
public void smoothMessageItem() {
if (mPostion.size() > 0) {
if (page == mPostion.size()) {
// 当前位置为最后后一个位置重置
page = 0;
}
LinearLayoutManager layoutManager = (LinearLayoutManager) mRfragment.recyclerView.getLayoutManager();
// 获取到所要移动到的postion
int postion = Integer.valueOf(mPostion.get(page));
// 单个item高度
int item = dp2px(62);
// 所有的移动距离都以 firstVisibleItemPosition 来做参照
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
// 获取到当前参照view的偏移量
int top = layoutManager.findViewByPosition(firstVisibleItemPosition).getTop();
// 移动目标位置大于参照view postion
// (这里item为等高)如果包含headview移动距离必须考虑到Headview的高度
if (postion > firstVisibleItemPosition) {
int transPostion = postion - firstVisibleItemPosition;
mRfragment.recyclerView.smoothScrollBy(0, (transPostion * item + top));
// 移动目标位置小于参照view postion
} else if (postion < firstVisibleItemPosition) {
int transPostion = firstVisibleItemPosition - postion;
mRfragment.recyclerView.smoothScrollBy(0, -(transPostion * item - top));
} else {
// 移动目标位置等于参照view postion
mRfragment.recyclerView.smoothScrollBy(0, top);
}
// 标记位置增加一为下一次移动做准备
page++;
}
}

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值