0

The question is not about what is the workaround as that has already been solved by using a custom layout-manager. My question is as to why android did not provide this functionality?

Is it because of the fact that wrap-content will make the recycler view compute dimension of all the child views again and again to set it's own dimension and is not a preferred behaviour and is not in the essence of using adapter-views? Or something else?

Msk
  • 857
  • 9
  • 16
  • Wouldn't it be preferable for it's `LayoutManager` to manage that as well as layouting of the items? – Shark Feb 24 '16 at 13:08
  • So what you mean is that by making the user set the layout manager, android suggests that you can take care of the recycler view wrap_content the way you want to? – Msk Feb 24 '16 at 13:12
  • No, before we get mixed up here - you inflate something into a recyclerview, that layout can have wrap_content just fine. But if there will be more than one item inflated in the recyclerview, you need an `RecyclerView.Adapter` and a `LayoutManager` - a `RecyclerView.LayoutManager` to be precise. – Shark Feb 24 '16 at 13:18
  • Thus, individual items can do `wrap_content` just fine, but also need help from the layout manager and it's `layout()` / `onLayout()` to know how to fit into their container; the RecyclerView in which they'll be inflated. But having `wrap_content` on the RecyclerView itself needs a bit of context and explanation, mostly to cover the "how big is the view when it's emtpy *BUT* it can't be 0" case. – Shark Feb 24 '16 at 13:22
  • I understand why the adapter is used i.e. to bind the data and the views. So, then why did android not provide a default manager with which can take care of the wrap_content like in the list view? – Msk Feb 24 '16 at 13:24
  • They did provide two-three default managers - the `LinearLayoutManager`, `StaggeredGridLayoutManager` and `GridLayoutManager`as you can clearly see [HERE](http://developer.android.com/reference/android/support/v7/widget/RecyclerView.LayoutManager.html) – Shark Feb 24 '16 at 13:27
  • Sorry if i'm taking too much time to understand, but then why do all these not enable the wrap_content property and how was this happening in the list view? – Msk Feb 24 '16 at 13:36
  • I need examples of how they don't enable `wrap_content`. Also, you need to understand that the RecyclerView is a parent-class of ListView only by idea (in theory); implementation-wise they're entirely different. But idea-wise (in theory) - ListView is a subclass of RecyclerView (even though they don't share any implementation details) – Shark Feb 24 '16 at 13:58
  • So if you place just a single recycler view in a layout and set height to wrap content, the recycler view will have height as that of the parent. – Msk Feb 24 '16 at 14:31
  • https://code.google.com/p/android/issues/detail?id=74772 – Msk Feb 24 '16 at 14:31
  • That thread is from 2014. It's 2016 now. `wrap_content` works as far as I know, but **again** what do you expect wrap_content to do in a empty recyclerview? wrap it to 0? I don't mind that it behaves as `match_parent` while empty, as that's how I mostly use them as well :/ As someone else said it - `I don't think setting wrap_content to RecyclerView doesn't make much sense, just as it doesn't for ListView, because it can't know the size of all of the items without going through all of them, yet there can be tons of items (even infinite or close to it in some cases).` – Shark Feb 24 '16 at 14:38
  • Hey. New version of support library is out. RecyclerView supports 'wrap_content' now :D – Shark Feb 25 '16 at 09:21

1 Answers1

3

The new support library 23.2.0 has fixed this issue.

Gaurav
  • 667
  • 2
  • 13
  • 28