Understanding RecyclerView setHasFixedSize

后端 未结 8 2046
闹比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:31

    Can confirm setHasFixedSize relates to the RecyclerView itself, and not the size of each item adapted to it.

    You can now use android:layout_height="wrap_content" on a RecyclerView, which, among other things, allows a CollapsingToolbarLayout to know it should not collapse when the RecyclerView is empty. This only works when you use setHasFixedSize(false) on the RecylcerView.

    If you use setHasFixedSize(true) on the RecyclerView, this behavior to prevent the CollapsingToolbarLayout from collapsing does not work, even though the RecyclerView is indeed empty.

    If setHasFixedSize was related to the size of items, it shouldn't have any effect when the RecyclerView has no items.

提交回复
热议问题