我用AppBarLayout>的组合创建了布局CollapsingToolbarLayout> RelativeLayout
<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:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="240dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="@android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<RelativeLayout
android:id="@+id/layoutHeader"
android:layout_width="match_parent"
android:layout_height="240dp"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax">
<ImageView
android:id="@+id/ivCoverImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY" />
<RelativeLayout
android:id="@+id/layoutImgWrapper"
android:layout_width="74dp"
android:layout_height="74dp"
android:layout_marginLeft="@dimen/app_normal_padding"
android:layout_marginRight="20dp"
android:layout_marginTop="100dp"
android:background="@drawable/rest_image_wrapper"
android:padding="3dp">
<ImageView
android:id="@+id/ivRestaurant"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
/>
</RelativeLayout>
<com.test.widget.CustomTextView
android:id="@+id/tvRestaurantName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/layoutImgWrapper"
android:layout_marginBottom="4dp"
android:layout_toEndOf="@+id/layoutImgWrapper"
android:layout_toRightOf="@+id/layoutImgWrapper"
android:text="Benjy's"
android:textColor="@color/white"
android:textSize="18sp"
app:typeface="fonts/proximanova_semibold.ttf" />
<RatingBar
android:id="@+id/ratingBar"
style="@style/CustomRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvRestaurantName"
android:layout_toEndOf="@+id/layoutImgWrapper"
android:layout_toRightOf="@+id/layoutImgWrapper"
/>
<com.test.widget.UnderlinedTextView
android:id="@+id/tvReviews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/ratingBar"
android:layout_marginLeft="10dp"
android:layout_toEndOf="@+id/ratingBar"
android:layout_toRightOf="@+id/ratingBar"
android:autoLink="web"
android:text="0 Review"
android:textColor="@color/white"
android:textSize="14sp"
app:underlineColor="@color/rest_review_underline_color"
app:underlineWidth="1dp" />
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="top"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleMarginTop="15dp" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="50dp"
app:tabIndicatorColor="@color/primary_dark_color"
app:tabIndicatorHeight="@dimen/tab_indicator_height"
app:tabMode="scrollable" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
当我重新扩展布局时,顶部(工具栏,标签等)在ICS和果冻豆中不起作用。我测试过,它在所有版本上都有效。 我认为在较低的操作系统中折叠(它需要工具栏的高度)后顶部高度是固定的。让我建议任何解决方案。 提前致谢。