Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dsoutw opened this issue Nov 7, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@dsoutw
Copy link

dsoutw commented Nov 7, 2023

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!

@dsoutw dsoutw added the bug Something isn't working label Nov 7, 2023
@dsoutw dsoutw changed the title Setting match_parent in a child causes display and stability problem in its descendant views Setting match_parent in a child causes display and stability problems in its descendant views Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant