使用状态栏和底栏折叠工具栏问题。 Fitssystemwindows =“true”无效

问题描述 投票:2回答:1

我不能让我的CoordinatorLayout使用折叠工具栏和嵌套ScrollView来工作。

在CoordinatorLayout之外的任何设置上设置fitssystemwindows =“true”没有或有负面影响。 App Theme具有该属性

<item name="android:windowTranslucentStatus">true</item>

使状态栏透明。

我的问题是:1。图像向下滚动太远,以便半透明状态栏采用蓝色工具栏颜色(当工具栏未100%展开时,ImageView可见)。 enter image description here enter image description here

  1. 系统的Bottom Bar隐藏了我的NestedScrollView的一部分。 enter image description here

这是我的布局:

<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.application.collapsingtoolbarexample.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="250dp"
    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"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/goslings"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"/>

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

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#dfdddd"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="10dp"
        >

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />


    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

android
1个回答
0
投票

您需要适合系统窗口(除工具栏之外的所有内容),还要在图像上设置高度而不是CollapsingToolbar

android:fitsSystemWindows="true"

所以最终的代码是

<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.application.collapsingtoolbarexample.MainActivity">

<android.support.design.widget.AppBarLayout
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            android:src="@drawable/goslings"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"/>

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

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#dfdddd"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="10dp"
        >

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />

        <include layout="@layout/card_layout" />


    </LinearLayout>

</android.support.v4.widget.NestedScrollView>
© www.soinside.com 2019 - 2024. All rights reserved.