android - collapsing toolbar and fragment layout not working together

后端 未结 2 1893
南方客
南方客 2021-01-25 01:23

In my app I have two fragments and a MainActivity. The activity_main.xml contains a collapsing toolbar which works perfectly for me when the fragments are empty. In my first fra

2条回答
  •  时光取名叫无心
    2021-01-25 02:27

    You haven't mentioned where the fragments are attached - I assume within the NestedScrollView? If not, that's where they should go.

    The problem is most likely the ListView within the fragment - unlike a RecyclerView, it does not implement NestedScrollingChild2 and ScrollingView, which are required for the collapsing toolbar functionality.

    Replace the ListView with a RecyclerView and make sure the fragments are within the NestedScrollView that has app:layout_behavior="@string/appbar_scrolling_view_behavior" and it should work.

提交回复
热议问题