Android 如何在折叠工具栏布局中折叠时删除透明工具栏填充

Android 如何在折叠工具栏布局中折叠时删除透明工具栏填充,android,toolbar,android-collapsingtoolbarlayout,Android,Toolbar,Android Collapsingtoolbarlayout,我在我的应用程序中使用了CollazingToolbarLayout,但当它被折叠时,工具栏中有一个marginLeft和marginRight,如下图所示。 当我将工具栏背景设置为非透明(如红色)时,它看起来正常。 那么我应该如何删除边距呢? 我希望它是下面这个,但背景是透明的 我的xml代码是 <android.support.design.widget.AppBarLayout android:id="@+id/appbarLayout" android:

我在我的应用程序中使用了CollazingToolbarLayout,但当它被折叠时,工具栏中有一个marginLeft和marginRight,如下图所示。
当我将工具栏背景设置为非透明(如红色)时,它看起来正常。
那么我应该如何删除边距呢?

我希望它是下面这个,但背景是透明的

我的xml代码是

    <android.support.design.widget.AppBarLayout
    android:id="@+id/appbarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/transparent">
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:collapsedTitleGravity="center_horizontal"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:expandedTitleGravity="center_horizontal"
        app:statusBarScrim="@color/transparent"
        app:contentScrim="@color/transparent"
        app:expandedTitleTextAppearance="@style/CollapsingToolbarLayoutExpandedText"
        app:collapsedTitleTextAppearance="@style/CollapsingToolbarLayoutCollapsedText"
        app:expandedTitleMarginTop="0dp"
        app:expandedTitleMarginBottom="20dp">

        <View
            android:id="@+id/venueImage"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7"/>


        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/transparent"
            android:layout_marginTop="@dimen/status_bar_height"
            app:layout_collapseMode="pin"
            app:contentInsetLeft="0dp"
            app:contentInsetRight="0dp"/>

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

app:elevation=“0dp”
添加到
AppBarLayout
小部件中为我修复了这个问题


同样在我的布局中,我有
AppBarLayout
嵌套在
CoordinatorLayout
中,而你的则相反。

app:elevation=“0dp”
添加到
AppBarLayout
小部件中,为我解决了这个问题


同样在我的布局中,我有
AppBarLayout
嵌套在
CoordinatorLayout
中,而你的则相反。

你也可以在
AppBarLayout
中设置
android:stateListAnimator
空值;差不多

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stateListAnimator="@null"> // This works
//这很管用

您还可以在
AppBarLayout
中设置
android:stateListAnimator
null;差不多

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stateListAnimator="@null"> // This works
//这很管用