RecyclerView的滚动事件OnScrollListener研究 http://www.open-open.com/lib/view/open1477623086381.html
滚动参数 http://www.tuicool.com/articles/7RzUjaR http://www.open-open.com/lib/view/open1477623086381.html
//此方法只是关闭软键盘 private void hintKbTwo() { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); if(imm.isActive()&&getCurrentFocus()!=null){ if (getCurrentFocus().getWindowToken()!=null) { imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } }
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); if (newState == SCROLL_STATE_DRAGGING) { hintKbTwo(); } }
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int juli = getScollYDistance();
int firstVisibleItem = mManager.findFirstVisibleItemPosition();
int section = getSectionForPosition(firstVisibleItem);
int nextSection = getSectionForPosition(firstVisibleItem + 1);
int nextSecPosition = getPositionForSection(+nextSection);
if (firstVisibleItem != lastFirstVisibleItem) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) titleLayout.getLayoutParams();
params.topMargin = 0;
titleLayout.setLayoutParams(params);
title.setText(mData.get(getPositionForSection(section)).getSortLetters());
}
if (nextSecPosition == firstVisibleItem + 1) {
View childView = recyclerView.getChildAt(0);
if (nextSecPosition == firstVisibleItem + 1) {
int titleHeight = titleLayout.getHeight();
int bottom = childView.getBottom();
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) titleLayout.getLayoutParams();
if (bottom < titleHeight) {
float pushedDistance = bottom - titleHeight;
params.topMargin = (int) pushedDistance;
titleLayout.setLayoutParams(params);
} else {
if (params.topMargin != 0) {
params.topMargin = 0;
titleLayout.setLayoutParams(params);
}
}
}
}
lastFirstVisibleItem = firstVisibleItem;
}
});
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有