liftOnScroll not working with ViewPager?
See original GitHub issueOverview
When I set app:liftOnScroll="true"
to my AppBarLayout, and then launch the app, I don’t see any shadow, and scrolling down or up doesn’t work.
My Layout:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:liftOnScroll="true">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:theme="?android:toolbarStyle"
app:layout_scrollFlags="scroll|enterAlways"
app:title="@string/app_name"
app:titleTextAppearance="@style/ToolbarTitleAppearance"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
style="@style/TabLayout.Style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="always"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Version number
com.google.android.material:material:1.0.0-beta01
Operating system and device
- OnePlus 6 with Android 8.1
- Emulator (Pixel 2 XL) Android P (latest DP)
Related issues
Someone already posted a similar issue (#140 ) but his issue was fixed by removing the bottom margin of his NestedScrollView. However I’m using a ViewPager, and I don’t have any bottom margin in my layout.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:9 (3 by maintainers)
Top Results From Across the Web
[AppBarLayout] liftOnScroll not working with ViewPager ...
When I set app:liftOnScroll="true" to my AppBarLayout, and then launch the app, I don't see any shadow, and scrolling down or up doesn't...
Read more >Androidx ViewPager not working with scrolling view behavior
But I've been playing with the liftOnScroll, both programatically and just on xml. Gonna update the issue. – 4gus71n. Nov 1, 2018 at...
Read more >Handling Scrolls with CoordinatorLayout - CodePath Cliffnotes
The first step is to make sure you are not using the deprecated ActionBar. ... Keep in mind that ScrollView does not work...
Read more >RecyclerView to ViewPager2 with MaterialViewPager | Android
Create ViewPager adapter; 6. ... let's copy the strings for showing titles and other data, colors, drawables and styles for the app.
Read more >How to add CastButton to MaterialToolbar (not appcompat ...
[Solved]-How to add CastButton to MaterialToolbar (not appcompat Toolbar)-kotlin ... app:liftOnScroll="true"> <com.google.android.material.appbar.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can now set
liftOnScrollTargetViewId
on yourAppBarLayout
to point to yourViewPager
directly. Or in my case, aRecyclerView
inside of theViewPager
(but make sure eachRecyclerView
has a unique id and you updateliftOnScrollTargetViewId
in theViewPager
’sonTabSelected
).If by any chance you have multiple fragments with the same layout in ViewPager, having unique IDs for scroll containers and communicating them to AppBar is a whole new can of headache.
While changing ID of view after getting an initial reference to them (using
findViewById
or with KTX view binding) works, I can’t help but feel like it’s going to come and bite me later, or not me, but another unsuspecting developer who will try to get the view using its original ID for whatever reason.The safest way to do it, that I’m aware of, is by having an ID for each fragment in ViewPager stored in ids.xml. This adds a lot of manual labor, especially if you have a good number of ViewPager (also, it will not work with dynamically added fragments, if that’s your things).
Anything else I’m missing?