我有一个包含视图树的布局,如下所示:
当用户滚动到
我尝试了一些文章,例如(https://dev59.com/kVwY5IYBdhLWcg3wJk8q#44327350--它创建了一个假视图,不能与标题进行交互),以及一些库,例如(https://github.com/emilsjolander/StickyScrollViewItems--相当长时间没有更新),但我不觉得它好。
这方面有什么好的经验吗?我看到很多应用程序使用它,但不确定Google是否原生支持它,也不确定我错过了什么。
任何帮助都将不胜感激。谢谢。
更新于2021年12月13日
- ConstraintLayout
-- TextView
- WebView
- TabLayout (1) (3 tabs)
- ViewPager (1)
- TabLayout (2) (4 tabs)
- ViewPager (2)
当用户滚动到
ViewPager(1)
时,TabLayout(1)
将会固定在顶部,并且能够像火币app中下面的GIF所示一样进行交互。如果用户继续滚动到ViewPager(2)
,它将推出TabLayout(1)
并将TabLayout(2)
固定在顶部。我尝试了一些文章,例如(https://dev59.com/kVwY5IYBdhLWcg3wJk8q#44327350--它创建了一个假视图,不能与标题进行交互),以及一些库,例如(https://github.com/emilsjolander/StickyScrollViewItems--相当长时间没有更新),但我不觉得它好。
这方面有什么好的经验吗?我看到很多应用程序使用它,但不确定Google是否原生支持它,也不确定我错过了什么。
任何帮助都将不胜感激。谢谢。
更新于2021年12月13日
<?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>
我目前正在使用这个库 StickyScrollView,它的功能正常,但包含一些小缺陷。我仍然希望找到其他更稳定的方法。谢谢。