androidx / constraintlayout

ConstraintLayout is an Android layout component which allows you to position and size widgets in a flexible way
Apache License 2.0
1.06k stars 177 forks source link

Setting match_parent in a child causes display and stability problems in its descendant views #846

Open dsoutw opened 7 months ago

dsoutw commented 7 months ago

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":

  1. The order of the displayed list is incorrect
  2. It generates a non-stooping loop running in the background
  3. 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:

  1. ConstraintLayout
  2. ViewPager2
  3. data binding
  4. 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!