Android Collapsing工具栏有太多填充

时间:2016-02-07 07:00:18

标签: android android-design-library android-collapsingtoolbarlayout

我有一个折叠工具栏,如下所示:
        

    <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:collapsedTitleGravity="right"
            app:paddingStart="5dp"
            app:titleEnabled="true"
            app:expandedTitleGravity="top|center_horizontal"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
            app:expandedTitleMarginEnd="0dp"
            app:expandedTitleMarginStart="0dp"
            app:expandedTitleMarginTop="0dp">

        <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent">
            <ImageView
                    android:id="@+id/backdrop"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax"/>
            <com.ashojash.android.customview.VenueScoreIndicator android:layout_width="match_parent"
                                                                 android:layout_height="match_parent"
                                                                 android:layout_alignParentBottom="true"
                                                                 android:id="@+id/venueScoreIndicator"/>
        </RelativeLayout>

        <!-- As our statusBar is transparent below and content is moved behind our toolbar has to include the padding on top so we use this area -->
        <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:paddingRight="8dp"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

image showing the extra padding
如您所见,在折叠标题的顶部和底部有一些额外的填充,我没有看到任何选项将app:collapsedTitlePaddingTop设置为0dp。
我错过了什么?

2 个答案:

答案 0 :(得分:0)

我认为问题是具有match_parent高度的RelativeLayout。尝试删除它,如果问题已经解决,请以某种方式在没有match_parent高度

的情况下进行布局

答案 1 :(得分:0)

请试试这个......这会很有帮助

<?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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</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" />