Use ExpandableLinearLayout if your child views change size (e.g., when loading content from a server). This is the recommended layout to use inside a RecyclerView.
RecyclerView Integration
When using inside a RecyclerView, you must disable view recycling for the holder and notify the layout that it is in a recycler view context:
- Call
holder.setIsRecyclable(false). - Call
expandableLayout.setInRecyclerView(true).
Recalculating Size
If child content changes (like setting text from a server), call initLayout() to recalculate the size of the children.
// resize expandable layout
ExpandableLinearLayout expandableLayout = (ExpandableLinearLayout) findViewById(R.id.expandableLayout);
child.setText("Sets text from a server");
expandableLayout.initLayout(); // Recalculate size of children
// recycler view
// you must set a ViewHolder#setIsRecyclable(false) and ExpandableLinearLayout#setInRecyclerView(true)
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.setIsRecyclable(false);
holder.expandableLinearLayout.setInRecyclerView(true);
}