我正在使用viewpager,它具有自己的CollapsingToolbarLayout。 但有时,特定页面的视图有问题(状态栏下方的主页按钮也是如此)。
当我删除工具栏的android:fitsSystemWindows并将边距顶部设置为24dp时,工具栏已修复,但cardview的边距顶部保持错误。
发生了什么事?
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:ignore="MergeRootFrame">
<android.support.design.widget.AppBarLayout
android:id="@+id/toolbar_det"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_layout_size"
app:elevation="@dimen/elevation_app_bar"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:expandedTitleMarginEnd="@dimen/expanded_title_margin_end"
app:expandedTitleMarginStart="@dimen/expanded_title_margin_start"
app:layout_scrollFlags="scroll"
app:toolbarId="@id/toolbar">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lightPrimaryColor" />
<ImageView
android:id="@+id/image_view_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:transitionName="@string/shared_transition" />
<LinearLayout
android:id="@+id/background_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
tools:background="@drawable/gradient_black"
android:orientation="vertical"
android:padding="@dimen/default_margin">
<TextView
android:id="@+id/text_view_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:paddingBottom="@dimen/detail_metabar_title_bottom_padding"
android:textColor="@color/white"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_view_info"
android:fontFamily="sans-serif-condensed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white" />
</LinearLayout>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_article_detail"
android:fitsSystemWindows="false"
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/nestedScrollView"
android:layout_width="match_parent"
android:clipToPadding="true"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:layout_width="match_parent"
android:paddingBottom="16dp"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/card_view_margin"
android:clickable="true"
android:focusable="true"
android:layout_marginBottom="16dp"
android:padding="@dimen/card_padding"
app:cardElevation="@dimen/cardview_default_elevation">
<TextView
android:id="@+id/text_view_body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/body_margin"
android:textColor="@color/primaryText"
android:textColorLink="@color/colorAccent"
tools:textSize="@dimen/text_size_body" />
</android.support.v7.widget.CardView>
</FrameLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_padding"
android:contentDescription="@string/action_share"
android:src="@drawable/ic_share"
app:elevation="@dimen/elevation_fab"
app:fabSize="normal"
app:layout_anchor="@id/toolbar_det"
app:layout_anchorGravity="bottom|right|end"
tools:background="?android:attr/selectableItemBackgroundBorderless" />
</android.support.design.widget.CoordinatorLayout>