【发布时间】:2015-11-28 11:41:30
【问题描述】:
我正在尝试使用以下结构实现视图
MainActivity
CoordinatorLayout
ViewPager
Fragment (root view, RelativeLayout)
TextView
RecyclerView
或者,有一个 RecyclerView 和一个 Fragment 中的兄弟,放置在一个 ViewPager 中,在一个 CoordinatorLayout 中。
在这个视频中可以看到布局,以及问题:https://youtu.be/1oAqEpg7N4I
我希望 TextView 与 RecyclerView 一起滚动,但是 TextView 当前保持在原位,而 RecyclerView 在其下方自行滚动。您可以在视频中看到效果。
我找到了在 ViewPager 中处理 RecyclerView 的演示,但我找不到任何像我一样使用标题的演示。
我尝试引入一个 NestedScrollView 作为 Viewpager 的父级,作为片段布局的根,而 ScrollView 只能有一个父级,所以我无法添加它来包装 TextView 和 RecyclerView。
这是我的 CoordinatorLayout 实现。如果需要,可以在 Github 以及 https://github.com/vidia/MaterialDiningCourts/blob/master/app/src/main/res/layout/activity_meal_view.xml 上找到它以获取上下文。
<android.support.design.widget.CoordinatorLayout
...
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
...
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay">
...
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foregroundGravity="top"
... />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
标签: android android-layout android-fragments android-appcompat