我有以下布局:
<?xml version="1.0" encoding="utf-8"?>
<nl.psdcompany.duonavigationdrawer.views.DuoDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScaleOpen="0.87"
app:marginFactor="0.7">
<nl.psdcompany.duonavigationdrawer.views.DuoMenuView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_menu_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:tag="@string/tag_menu"
app:footer="@layout/drawer_footer"
app:header="@layout/drawer_header" />
<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:tag="@string/tag_content"
android:translationZ="8dp">
<include layout="@layout/layout_toolbar" />
<FrameLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
</nl.psdcompany.duonavigationdrawer.views.DuoDrawerLayout>
包含布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:translationZ="4dp"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="exitUntilCollapsed|snap"
app:scrimAnimationDuration="250">
<!--
Toolbar Collapsing Layout
-->
<LinearLayout
android:id="@+id/collapsing_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="56dp"
android:orientation="vertical"
android:visibility="visible"
app:layout_collapseMode="parallax">
<TextView
android:id="@+id/collapsing_toolbar_title"
fontPath="@string/font_sf_ui_display_black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:textColor="@color/white"
android:textSize="24sp"
android:visibility="visible" />
<TextView
android:id="@+id/collapsing_toolbar_secondary_title"
fontPath="@string/font_sf_ui_display_regular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-3dp"
android:textColor="@color/dark_red"
android:textSize="@dimen/text_small"
android:visibility="visible" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin">
<RelativeLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingEnd="@dimen/margin_medium"
android:paddingStart="@dimen/margin_medium">
<!--
Toolbar TOP Layout
-->
<RelativeLayout
android:id="@+id/toolbar_top_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="?attr/actionBarSize">
<RelativeLayout
android:id="@+id/default_toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:visibility="visible">
<!-- Starting icons container -->
<FrameLayout
android:id="@+id/toolbar_left_icon_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/margin_small">
<ImageView
android:id="@+id/toolbar_hamburger"
android:layout_width="@dimen/toolbar_icon_size"
android:layout_height="@dimen/toolbar_icon_size"
android:layout_gravity="center"
android:tint="@color/white"
android:visibility="gone"
app:srcCompat="@drawable/ic_burger_menu_white" />
<ImageView
android:id="@+id/toolbar_start_icon"
android:layout_width="@dimen/toolbar_icon_size"
android:layout_height="@dimen/toolbar_icon_size"
android:layout_gravity="center"
android:tint="@android:color/white"
android:visibility="gone"
app:srcCompat="@drawable/ic_back_button_white" />
<TextView
android:id="@+id/toolbar_start_text_icon"
fontPath="@string/font_sf_ui_display_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Cancel"
android:textColor="@color/dark_red"
android:textSize="@dimen/text_medium"
android:visibility="gone"
app:srcCompat="@drawable/ic_back_button_white" />
</FrameLayout>
<!-- Step Progress Bar -->
<FrameLayout
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/toolbar_left_icon_container"
android:visibility="gone"/>
<!-- Main title centered in the toolbar -->
<LinearLayout
android:id="@+id/toolbar_title_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/toolbar_main_title"
fontPath="@string/font_sf_ui_display_black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="end"
android:maxLines="1"
android:text="View Offer"
android:textAllCaps="true"
android:textColor="@color/white"
android:textSize="15sp"
android:visibility="gone" />
<TextView
android:id="@+id/toolbar_secondary_title"
fontPath="@string/font_sf_ui_display_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-3dp"
android:text="last visit on 15-03"
android:textColor="@color/dark_red"
android:textSize="@dimen/text_small"
android:visibility="gone" />
</LinearLayout>
<!-- Secondary end icon -->
<ImageView
android:id="@+id/toolbar_secondary_end_icon"
android:layout_width="@dimen/toolbar_icon_size"
android:layout_height="@dimen/toolbar_icon_size"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/margin_small"
android:layout_toStartOf="@+id/toolbar_end_icon_container"
android:visibility="gone"
app:srcCompat="@drawable/ic_share_white" />
<!-- Primary end icon container-->
<FrameLayout
android:id="@+id/toolbar_end_icon_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true">
<ImageView
android:id="@+id/toolbar_primary_end_icon"
android:layout_width="@dimen/toolbar_icon_size"
android:layout_height="@dimen/toolbar_icon_size"
android:layout_gravity="center"
android:visibility="gone"
app:srcCompat="@drawable/ic_share_white" />
<!-- Badge counter container -->
<FrameLayout
android:id="@+id/toolbar_badge_counter_container"
android:layout_width="28dp"
android:layout_height="28dp"
android:visibility="gone">
<ImageView
android:id="@+id/toolbar_badge_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="4dp"
android:visibility="gone"
app:srcCompat="@drawable/ic_bell_notifications" />
<TextView
android:id="@+id/toolbar_badge_counter"
fontPath="@string/font_sf_ui_display_medium"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_gravity="end"
android:background="@drawable/circle_blue"
android:gravity="center"
android:text="3"
android:textColor="@color/white"
android:textSize="9sp"
android:visibility="gone" />
</FrameLayout>
<TextView
android:id="@+id/toolbar_right_text_icon"
fontPath="@string/font_sf_ui_display_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/dark_red"
android:textSize="@dimen/text_medium"
android:visibility="gone" />
</FrameLayout>
<Button
android:id="@+id/change_postal_code_button"
android:layout_width="wrap_content"
android:visibility="gone"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_small"
android:layout_toLeftOf="@+id/toolbar_end_icon_container"
android:background="@drawable/rounded_background_blue"
android:drawablePadding="@dimen/margin_small"
android:drawableStart="@drawable/ic_navigation_white"
android:minHeight="0dp"
android:paddingBottom="@dimen/margin_small"
android:paddingLeft="@dimen/margin_small_medium"
android:paddingRight="@dimen/margin_small_medium"
android:paddingTop="@dimen/margin_small"
android:text="1234 AA, Amsterdam"
android:textAllCaps="false"
android:textColor="@color/white" />
</RelativeLayout>
</RelativeLayout>
<!--
Toolbar BOTTOM Layout
-->
<LinearLayout
android:id="@+id/toolbar_bottom_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar_top_container"
android:orientation="vertical"
android:paddingBottom="@dimen/margin_medium"
android:visibility="gone">
<TextView
android:id="@+id/toolbar_bottom_title"
fontPath="@string/font_sf_ui_display_black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:text="View Offer"
android:textColor="@color/white"
android:textSize="24sp"
android:visibility="gone" />
<TextView
android:id="@+id/toolbar_bottom_secondary_title"
fontPath="@string/font_sf_ui_display_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-3dp"
android:text="last visit on 15-04"
android:textColor="@color/dark_red"
android:textSize="@dimen/text_small"
android:visibility="gone" />
<include
android:id="@+id/search_toolbar"
layout="@layout/layout_search_offers" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
它由一个带有CollapsingToolbarLayout的AppBarLayout组成,其中第一个孩子是作为折叠布局的Linear,以及当我需要底部非折叠时保持顶部条和静态底部的工具栏布局工具栏。
折叠效果很好,我可以设置我的工具栏只有顶部布局或仅底部但是当我将项目的可见性更改为Gone时,AppBarLayout(或者CollapsingToolbarLayout)不会调整大小并保持间距
片段更改后(我将视图设置为Gone以重置布局)
感谢您的时间;