From dc529b6640f02a16ff7d470c89bf2806f35d88c0 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 16 Dec 2022 13:57:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=92=AD=E9=97=B4?= =?UTF-8?q?=E9=95=BF=E6=9C=9F=E4=B8=8D=E5=8A=A8=E4=BC=9A=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E6=BB=9A=E5=8A=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/live/adapter/LiveChatAdapter.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java index e0a9e4b1f..3fc05e41a 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -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 = "聊天测试"; + /** * 判断是否滚到底部 *