我需要创建一个类似谷歌报摊的界面,这是一种 ViewPager (水平滚动)在一个折叠的标题(垂直滚动)。我的需求之一是使用在 GoogleIO 2015上提供的新的设计支持库。 (http://android-developers.blogspot.ca/2015/05/android-design-support-library.html)
基于 Chris Banes (https://github.com/chrisbanes/cheesesquare)创建的示例,我已经达到了这样一个点: 我能够使用一个基本的 LinearLayout (没有水平滚动)来实现折叠行为。
我试图用 ViewPager 替换 LinearLayout,结果得到了一个空白屏幕。我玩: 宽度,重量和各种视图组,但... 。还是一片空白。看起来 ViewPager 和 NestedScrollView 并不喜欢对方。
我尝试使用 HorizontalScrollView 来解决这个问题: 它可以工作,但是我失去了 PagerTitleStrip 功能的好处,而且我只关注一个面板(我可以在两个面板之间水平停止)。
现在我没有更多的想法,如果有人能带我找到解决办法..。
谢谢
这是我最新的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="@dimen/header_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include
layout="@layout/part_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/activity_main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/activity_main_nestedscrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v4.view.ViewPager
android:id="@+id/activity_main_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFA0"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>