RecyclerView smoothscroll不适用于许多项目

时间:2016-01-06 14:10:19

标签: android android-recyclerview

我想像periscope chat一样创建列表消息。这意味着它看起来像新的消息滑动,它正在移动其他项目。当我有超过5条消息时,我正在使用平滑滚动。所有看起来都很好但是在几条消息后,平滑滚动不起作用。

我覆盖了smoothScrollToPostion()方法

@Override
    public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state,
                                       int position) {
        LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
            @Override
            public PointF computeScrollVectorForPosition(int targetPosition) {
                return ResizableLayoutManager.this.computeScrollVectorForPosition(targetPosition);
            }

            @Override
            protected int calculateTimeForScrolling(int dx) {
                // Value of dx is 0 when is lot of message
                return 100;
            }

        };

        smoothScroller.setTargetPosition(position);
        startSmoothScroll(smoothScroller);
    }

课程ResizableLayoutManager已展开LinearLayoutManager

0 个答案:

没有答案