【问题标题】:NestedScrollView fix the view top inside NestedScrollViewNestedScrollView 修复 NestedScrollView 内部的视图顶部
【发布时间】:2020-03-29 20:33:43
【问题描述】:

我想在类似滚动的 Instagram 时将TabLayout 固定在顶部。有没有办法在NestedScrollView 中做到这一点?

NestedScrollView
-- ConstraintLayout
---- OtherViews
---- TabLayout
---- ViewPager

https://i.imgur.com/G5QcqaW.png

https://gist.github.com/buraktabn/c73cd04bed6a223471834756d6f32773

【问题讨论】:

  • 你能附上你实际布局的例子吗?
  • 我更新了问题。

标签: android android-layout kotlin android-recyclerview android-nestedscrollview


【解决方案1】:

你能不能这样做:

ConstraintLayout
-- OtherViews
-- TabLayout
-- NestedScrollView
---- ViewPager

这样 ViewPager 的内容会滚动吗?仅供参考,可能还值得一看 CoordinatorLayoutCollapsingToolbarLayout (https://material.io/develop/android/components/collapsing-toolbar-layout/),这将允许用户在向上滚动时重新获得部分屏幕。

【讨论】:

    【解决方案2】:

    您不能直接在NestedScrollView 中执行此操作,因为视图本身应该滚动内容。

    如果您要在顶部寻找固定的 TabLayout 且不会移动,您可以将 TabLayout 拉出 NestedScrollView 并将这两个视图包含在另一种布局类型下(例如 @ 987654328@、ConstraintLayout等)。

    如果您希望 TabLayout 在用户滚动时扩展和收缩,最好的选择是 CoordinatorLayout,它可以包含 NestedScrollView,然后在 CoordinatorLayout 的 @ 下实现您的 TabLayout 987654335@/CollapsingtoolbarLayout。该结构类似于:

    CoordinatorLayout
    - AppBarLayout
    -- CollapsingToolbarLayout
    --- [Your implementation of the `TabLayout`]
    -- NestedScrollView
    

    您可以在此处找到有关CoordinatorLayoutCollapsingToolbarLayout 的更多信息:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多