NestedScrollView+RecyclerView 滑动

2017-10-11  本文已影响96人  Mason啊

今天遇到一个问题,就是那个使用NestedScrollView+RecyclerView会卡顿,这样滑动起来会卡顿,给用户带来了很不好的体验,也是想着去解决一下。于是我上了百度,哈哈,别我找到了解决方案,我记录一下,也供大家参考一下。
在给RecyclerView设置layoutManager 的时候设置几个参数,我附上源码的解释,参数的意思我也大概的翻译一下,意思差不多,方便大家理解

LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    /**
     * When smooth scrollbar is enabled, the position and size of the scrollbar thumb is computed
     * based on the number of visible pixels in the visible items. This however assumes that all
     * list items have similar or equal widths or heights (depending on list orientation).
     * If you use a list in which items have different dimensions, the scrollbar will change
     * appearance as the user scrolls through the list. To avoid this issue,  you need to disable
     * this property.
     */
        //启用平滑滚动条
        layoutManager.setSmoothScrollbarEnabled(true);

        /**Defines whether the layout should be measured by the RecyclerView or the LayoutManager
         * wants to handle the layout measurements itself.
          */
        //自动测量
        layoutManager.setAutoMeasureEnabled(true);

        recyclerView.setLayoutManager(layoutManager);
      
        //@param hasFixedSize true if adapter changes cannot affect the size of the RecyclerView.
        recyclerView.setHasFixedSize(true);
        //嵌套设置为不可滑动
        recycerView.setNestedScrollingEnabled(false);

ok,到此就结束了

上一篇下一篇

猜你喜欢

热点阅读