[x] I have searched existing issues and confirmed this is not a duplicate
Issues and steps to reproduce
If any of your RecyclerView Viewholder items are inflated from XML, and those XML layouts use any of the Attributes for the children of a FlexboxLayout, for example app:layout_wrapBefore="true", then those attributes do not actually get applied to that item at runtime. The only way to set those flex attributes is programmatically, which is quite cumbersome.
Expected behavior
It would be great if the XML attributes on Viewholder items were respected.
I'd be happy to create a PR with this, but wanted to check first if this is a desired functionality.
Version of the flexbox library
2.0.1
Link to code
In this small sample, theapp:layout_wrapBefore="true" attribute on the ViewHolder is not respected and the item would not wrap to a new row when used with FlexboxLayoutManager
wrapping_view.xml
<TextView ..etc.. app:layout_wrapBefore="true" />
SampleAdapter.kt
class SampleAdapter : RecyclerView.Adapter<ViewHolder> {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = LayoutInflater.from(parent.context)
return WrappingViewHolder(inflater.inflate(R.layout.wrapping_view, parent, false))
}
class WrappingViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {}
}
I just spent my whole day trying to figure out why this wasn't working. Then I tried to set the layout params in my ViewHolder class and it did work...
Issues and steps to reproduce
If any of your RecyclerView Viewholder items are inflated from XML, and those XML layouts use any of the Attributes for the children of a FlexboxLayout, for example
app:layout_wrapBefore="true"
, then those attributes do not actually get applied to that item at runtime. The only way to set those flex attributes is programmatically, which is quite cumbersome.Expected behavior
It would be great if the XML attributes on Viewholder items were respected.
Code-wise, it'd be a simple change. The
FlexboxLayoutManager.LayoutParams
constructorLayoutParams(Context c, AttributeSet attrs)
(https://github.com/google/flexbox-layout/blob/master/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java#L2754) would have to be modified to extract the XML attributes and apply them (with the exception oflayout_order
, which is not supported).I'd be happy to create a PR with this, but wanted to check first if this is a desired functionality.
Version of the flexbox library
2.0.1
Link to code
In this small sample, the
app:layout_wrapBefore="true"
attribute on the ViewHolder is not respected and the item would not wrap to a new row when used withFlexboxLayoutManager
wrapping_view.xml
SampleAdapter.kt