Constraint Layout - Group visibility is not working inside dynamic module

Found a fix for this issue and I hope this will save time for someone else. It's strange but the reason for this issue is using the ConstraintLayout - Group, inside a dynamic module.

So the fix is in java code, once you got a reference to the group then set the reference ids using int array like below,

Group group = findViewById(R.id.group);
group.setReferencedIds(new int[]{R.id.btn_try_again_activity_dictionary, R.id.tv_message_activity_dictionary, R.id.iv_message_icon_activity_dictionary});

After this, it works as expected. Therefore no need to set visibility of individual views in the group.


I was having the same issue using ConstraintLayout v1.1.3. I was setting the visibility of the group in the XML but it wasn't working.

As ConstraintLayout v2.0.0 is already on beta, I migrated from v1.1.3 to v2.0.0-beta2 (check the latest version) and the issue is not happening anymore. I can now change the visibility of the group from XML or code without any problem.


Don't forget that you can use androidx.constraintlayout.widget.Group only if the parent view is constraintlayout if the parent is LinearLayout then it will not work, then you can try this answer which says that you add your required views inside FrameLayout or LinearLayout then set the visiblity of the sub parent view.


I have the same problem even though I'm on 2.0.0-beta8. group.visibility = View.GONE/VISIBLE doesn't work but group.isGone = true/false works