Understanding RecyclerView setHasFixedSize

后端 未结 8 2005
闹比i
闹比i 2020-11-28 01:52

I\'m having some trouble understanding setHasFixedSize(). I know that it is used for optimization when the size of RecyclerView doesn\'t change, fr

8条回答
  •  [愿得一人]
    2020-11-28 02:29

    The ListView had a similar named function that I think did reflect info about the size of the individual list item heights. The documentation for RecyclerView pretty clearly states it is referring to the size of the RecyclerView itself, not the size of its items.

    From the RecyclerView source comment above the setHasFixedSize() method:

     * RecyclerView can perform several optimizations if it can know in advance that changes in
     * adapter content cannot change the size of the RecyclerView itself.
     * If your use of RecyclerView falls into this category, set this to true.
    

提交回复
热议问题