In my case, I add OnLayoutChangeListener
to RecyclerView
, because when keyboard is hidden or showed, the RecyclerView
's bottom position will be changed. Codes like this:
recyclerView.addOnLayoutChangeListener(new 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) {
recyclerView.post(new Runnable() {
@Override
public void run() {
recyclerView.scrollToPosition(recyclerView.getAdapter().getItemCount() - 1);
}
});
}
}
});
And it works the same as set android:transcriptMode="alwaysScroll"
to ListView
.
la.getItemCount() - 1
? – Royston