Recyclerview smoothScrollToPosition()无效问题

Recyclerview smoothScrollToPosition()无效问题解决方法如下

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext) {                                               
    @Override                                                                                                               
    public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {                 
        LinearSmoothScroller smoothScroller =                                                                               
                new LinearSmoothScroller(recyclerView.getContext()) {                                                       
                    @Override                                                                                               
                    protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {                                 
                        // 返回:滑过1px时经历的时间(ms)。                                                                              
                        return 150f / displayMetrics.densityDpi;                                                            
                    }                                                                                                       
                                                                                                                            
                    @Override                                                                                               
                    public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) { 
                        return boxStart  - viewStart;                                                                       
                    }                                                                                                       
                };                                                                                                          
                                                                                                                            
        smoothScroller.setTargetPosition(position);                                                                         
        startSmoothScroll(smoothScroller);                                                                                  
    }                                                                                                                       
};                                                                                                                          

你可能感兴趣的:(Recyclerview smoothScrollToPosition()无效问题)