I have a layout that contains a tree of views like below:
- ConstraintLayout
-- TextView
- WebView
- TabLayout (1) (3 tabs)
- ViewPager (1)
- TabLayout (2) (4 tabs)
- ViewPager (2)
When user scrolls to ViewPager (1), TabLayout (1) will stick at top and able to interact like below GIF in Huobi app. And if user scrolls more to ViewPager (2), it will push TabLayout (1) out and TabLayout (2) will be sticked on top.
I tried some articles like (https://stackoverflow.com/a/44327350 -- It creates fake view and not able to interact header) and libs like (https://github.com/emilsjolander/StickyScrollViewItems -- quite too long no update) but i don't feel it good.
Any good practice on this? I see many apps used it but not sure will Google supports it natively and not sure what I missed.
Any help would be appreciated. Thanks.
Update 13/12/2021
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_color">
// Header
<include
android:id="@+id/layout_header"
layout="@layout/layout_header" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/wvChart"
android:layout_width="match_parent"
android:layout_height="@dimen/webview_height" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tl1"
android:layout_width="match_parent"
android:layout_height="@dimen/tablayout_height"
style="@style/TabLayoutStyle"
app:layout_constraintTop_toBottomOf="@id/wvChart"
app:tabTextAppearance="@style/TabLayoutTextStyle"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/vpg1"
android:minHeight="@dimen/viewpager_market_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_color"
app:layout_constraintTop_toBottomOf="@id/tl1"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tl2"
android:layout_width="match_parent"
android:layout_height="@dimen/tablayout_height"
style="@style/TabLayoutStyle"
app:layout_constraintTop_toBottomOf="@id/vpg1"
app:tabTextAppearance="@style/TabLayoutTextStyle"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/vpg2"
android:minHeight="@dimen/viewpager_market_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_color"
app:layout_constraintTop_toBottomOf="@id/tl2"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</layout>
I am currently using this lib StickyScrollView, it works as expected but contains minor bugs. I still want to find other stable way. Thanks.


