lucasr / twoway-view

[DEPRECATED] RecyclerView made simple
5.23k stars 1.02k forks source link

Adapter's should not have to deal with layout or view positioning #113

Open runningcode opened 10 years ago

runningcode commented 10 years ago

In the sample code, the LayoutAdapter class grabs the LayoutParams and decides how that view should be positioned in terms of number of columns. I think this breaks the principle of the RecyclerView.Adapter class. Instead, I propose that this should be done in the corresponding LayoutManager class. Perhaps the rows and columns which have different layouts should have a different ItemViewType. Does the LayoutManager have access to the ItemViewType? If so, it could use this to determine the number of columns

lucasr commented 9 years ago

You're right. This is just a little hack to force child views to have different layout params. It's especially handy for development. In practice, apps should be defining spans and sizes in the layout files (and related styles) for each view type.

lucasr commented 9 years ago

I'll update the sample to use item types, just so that TwoWayView users don't assume that setting LayoutParams in the adapter is the way to go.

nschwermann commented 9 years ago

I'm not understanding what you are suggesting here. It makes sense (to me) to have a view type that would want to be a different span size based on its bound data. Are you saying this is a bad idea?

lucasr commented 9 years ago

@schwiz I meant the opposite ;-) View types is the right thing to do here. I've been been abusing the sample app for development purposes. I'll update it to use view types to avoid confusion.

nschwermann commented 9 years ago

Oh good, I thought I followed your example but I guess I realized this unconsciously :-)

lucasr commented 9 years ago

With that said, there are valid situations to tweak LayoutParams in the adapter. For example, if you want to dynamically define the RecyclerView layout e.g. if spans are not necessarily associated with specific view types.