Setting match_parent in a child causes display and stability problems in its descendant views #846
Description
According to the conversation in #231, setting match_parent in a child of a "ConstraintLayout" while removing all conflicting constraints is a valid layout configuration. However, I discovered an example that shows such configuration causes display and stability problem in its descendant views.
The problem can be reproduced by this minimal example:
https://github.com/dsoutw/Android-RecyclerView-Bug
In this example, there a child view of a "ConstraintLayout" with "match_parent" set.
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tab_layout" />
This generates problems in a "RecyclerView" which is a descendant view of the "ViewPager2":
- The order of the displayed list is incorrect
- It generates a non-stooping loop running in the background
- Some views freeze
If the code is replaced by the following, then the problems disappear.
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tab_layout" />
A more detailed description can be found on the Readme file.
However, I am not sure if the problem is really caused by the "ConstraintLayout" and it is hard for me to decide where to file this bug report. According to some observations, having the 4 components with some specific configuration are required to reproduce the problem:
- ConstraintLayout
- ViewPager2
- data binding
- RecyclerView
On the other hand, this indicates that such problems might be hard for unit tests to identify.
Thanks for taking a look into the details!