问题:常见的滑动到最后一行但是显示不全的情况?
如果以下方法还是不行,可以考虑添加一定的延时
1.普通场景下滑动到最后一行
recyclerView.scrollToPosition(mAdapter.getData().size() - 1);
2.弹出软键盘时滑动到最后一行
recyclerView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
if (bottom < oldBottom) {
linearLayoutManager.smoothScrollToPosition(recyclerView, null, mAdapter.getItemCount());
}
});
如果不生效,尝试另一种
recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v,int left, int top, int right, int bottom,int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (bottom < oldBottom) {
final int lastAdapterItem = mAdapter.getItemCount() - 1;
recyclerView.post(new Runnable() {
@Override
public void run() {
int recyclerViewPositionOffset = -1000000;
View bottomView = linearLayoutManager.findViewByPosition(lastAdapterItem);
if (bottomView != null) {
recyclerViewPositionOffset = 0 - bottomView.getHeight();
}
linearLayoutManager.scrollToPositionWithOffset(lastAdapterItem, recyclerViewPositionOffset);
}
});
}
});
}
网友评论