一開始需求是每次有新的訊息要在最下面
然後就很突然的,將 RecyclerView 設置為倒序
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(),
LinearLayoutManager.VERTICAL, true); // 列表翻轉
linearLayoutManager.setStackFromEnd(true); // 列表在底部開始展示, 反轉後由上面開始展示
rvMessagesChat.setLayoutManager(linearLayoutManager);
rvMessagesChat.setHasFixedSize(true);
rvMessagesChat.setAnimation(null);
但是在加載新資料的時候,舊資料會被擠下去
int beforeSize = mList.size();
int afterSize = model.vModelRecord.size();
profileMessagesChatAdapter.addList(model.vModelRecord);
profileMessagesChatAdapter.notifyItemRangeInserted(beforeSize, afterSize);
所以需要新增這行,這樣就不會有擠壓的動畫
rvMessagesChat.setAnimation(null);
沒有留言:
張貼留言