我正在尝试“重新创建”(类似于)Play 报亭布局。根据文档, CoordinatorLayout 的一般结构是
<CoordinatorLayout>
<!— view that shrinks —>
<AppBarLayout>
<CollapsingToolbarLayout>
…
</CollapsingToolbarLayout>
</AppBarLayout>
<!— view that scrolls —>
<SomeScrollView >
….
</SomeScrollView>
</CoordinatorLayout>
除了当我查看 Newsstand 应用程序时,我能看到的是它SomeScrollView
实际上是 TabLayout 的 ViewPager。对于我的特殊情况,我的主要问题是我SomeScrollView
必须是某种片段容器。所以基本上我想要的是
-------
| A |
| |
-------
| B |
| |
-------
其中 A 是可折叠部分,B 是滚动部分。同样,对于我的案例 B 是动态片段的容器。所以 A 会有一个 TabLayout,当用户点击一个选项卡时,它会导致 B 中的可见片段发生变化。B 中的片段将包含 RecycleView 或可滚动的 TextView。(实际上其中一个 Fragments 是一个 FrameLayout,它同时包含一个 RecycleView 和一个 TextView,其中任何一个都是一次可见的)
到目前为止,这是我的代码:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- collapsing view -->
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include
…
/>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags=“…”
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!-- scrolling view -->
<android.support.v4.view.ViewPager
android:id="@+id/main_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</android.support.v4.view.ViewPager>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|right|end"
android:src="@drawable/ic_add"
android:layout_margin="@dimen/minor_horizontal_margin"
android:clickable="true"/>
</android.support.design.widget.CoordinatorLayout>
有人可以帮我完成吗?