我的布局有一个奇怪的问题。 我有一个带有CollapsingToolBarLayout的CoordinatorLayout 。 我有一个透明的状态栏,可以在顶部更好地显示图像。 因此,我在此ImageView上设置了fitsSystemWindow 。 我现在遇到的问题是,当工具栏完全合拢时,工具栏的顶部滚动到系统状态栏的后面。 有没有办法防止这种行为?
这是屏幕截图:
这是我的布局:
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:id="@+id/coordinatorLayout">
android:id="@+id/main_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
android:id="@+id/main_collapsing"
android:layout_width="match_parent"
android:layout_height="350dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="140dp"
app:expandedTitleMarginBottom="90dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
app:layout_collapseMode="parallax"
android:id="@+id/icon"
android:transitionName="pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/missing_album_art"
android:tint="#AA000000"
android:fitsSystemWindows="true"/>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
app:layout_collapseMode="parallax">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:padding="20dp"
android:orientation="horizontal">
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/smallicon"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom"
android:padding="20dp">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/artist"
android:ellipsize="end"
android:singleLine="true"
android:textSize="24sp"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:id="@+id/date"/>
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/list"
android:dividerHeight="2dp"
android:transitionName="bottom">
另外,在创建活动时,我会稍微调整布局参数:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);