android / codelab-constraint-layout

Constraint Layout Codelab
https://codelabs.developers.google.com/codelabs/constraint-layout/
Apache License 2.0
471 stars 242 forks source link

2.0.0-beta4 - ViewPager2 inside constraint layout #81

Open Nikochaix opened 4 years ago

Nikochaix commented 4 years ago

ContraintLayout: 2.0.0-beta4 ViewPager2: 1.0.0

When a constraint layout contains a viewpager2, it's children doesn't have focus (not clickable).

` <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent">

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/pager_bridge"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/navigation_bridge"
        app:layout_constraintTop_toTopOf="parent" />

... `

In my case, the view pager contains recycler views. The view holders are not clickable. When I use a frame layout or a linear layout, the view holders are clickable

rmazajev commented 4 years ago

We have same problem. Another problem which we have, then we use ViewPager2 with RecyclerView, after scrolling RecycleView sometimes items are empty. We use data binding.

vainquit commented 4 years ago

I have the very similar problem. I have a viewpager2 which links two fragments. Inside the fragment A there is a expandablelistview. When I first come into the the first page, where the fragment A is located and initialized first time, the expandablelistview works well. While when I come into the seconde page, and return back to the first page, the expandablelistview can't be even clicked. Then I set a button with OnClick event, where it tell the expandablelistview to request focus. So when I come to page 2 and return back to page 1, and click the button, then the expandablelistview can react to click event, i.e., it can expand and collapse as normal. So I guess the viewpager2 may lead to a problem of lossing focus.

I search on stackoverflow, and I see this answer: https://stackoverflow.com/questions/56590340/fragments-in-viewpager2-does-not-respond-to-clicks-if-scroll-position-is-0

The answer tells clearly that, he met the same issue and after changing the parent layout of viewpager2 from constraintlayout to linearlayout, the bug disappeared. I guess that's the point, but I can't do that like him, because my project has used constraintlayout everywhere and includes a lot of items, which will be hard to make a replacement.

I hope the post will be seen by more people and developers.