Open runningcode opened 10 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.
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.
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?
@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.
Oh good, I thought I followed your example but I guess I realized this unconsciously :-)
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.
In the sample code, the
LayoutAdapter
class grabs theLayoutParams
and decides how that view should be positioned in terms of number of columns. I think this breaks the principle of theRecyclerView.Adapter
class. Instead, I propose that this should be done in the correspondingLayoutManager
class. Perhaps the rows and columns which have different layouts should have a differentItemViewType
. Does the LayoutManager have access to theItemViewType
? If so, it could use this to determine the number of columns