修复直播间长期不动会自动停止滚动的问题

This commit is contained in:
zlzw 2022-12-16 13:57:00 +08:00
parent 488cc192b2
commit dc529b6640

View File

@ -12,6 +12,7 @@ import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -63,6 +64,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
private LinearLayoutManager mLayoutManager;
private IMLoginModel model;
private int mRecyclerViewScrolledDx, mRecyclerViewScrolledDy;
private int mPosition;
@ -121,6 +123,15 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
mRecyclerView = recyclerView;
mLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
mRecyclerViewScrolledDx = dx;
mRecyclerViewScrolledDy = dy;
Log.i(TAG, "onScrolled: dx = " + dx + ", dy = " + dy);
}
});
}
class RedPackVh extends RecyclerView.ViewHolder {
@ -379,8 +390,15 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
mList.remove(0);
}
mList.add(bean);
if (isSlideToBottom(mRecyclerView)) {
int sum = (mRecyclerView.computeVerticalScrollExtent() + mRecyclerView.computeVerticalScrollOffset());
Log.i(TAG, "Extent=" + mRecyclerView.computeVerticalScrollExtent() +
"|Offset=" + mRecyclerView.computeVerticalScrollOffset() +
"|sum=" + sum +
"|Range=" + mRecyclerView.computeVerticalScrollRange() +
"|content=" + bean.getContent() +
((sum >= mRecyclerView.computeVerticalScrollRange()) ? "" : "|停止滑动")
);
if (isSlideToBottom(mRecyclerView) || mRecyclerViewScrolledDy == 0) {
scrollToBottom(mRecyclerView);
} else {
Bus.get().post(new LiveAudienceEvent()
@ -409,6 +427,8 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
});
}
String TAG = "聊天测试";
/**
* 判断是否滚到底部
*