Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用NestedScrollView的Android Coordinator布局不折叠工具栏_Android_Android Toolbar_Android Coordinatorlayout - Fatal编程技术网

使用NestedScrollView的Android Coordinator布局不折叠工具栏

使用NestedScrollView的Android Coordinator布局不折叠工具栏,android,android-toolbar,android-coordinatorlayout,Android,Android Toolbar,Android Coordinatorlayout,尝试使用嵌套的滚动视图实现协调器布局,该视图包含2个片段容器,这些容器以垂直顺序显示许多片段。但是,滚动不会折叠我的工具栏。这是密码 活动布局 <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="htt

尝试使用嵌套的滚动视图实现协调器布局,该视图包含2个片段容器,这些容器以垂直顺序显示许多片段。但是,滚动不会折叠我的工具栏。这是密码

活动布局

    <?xml version="1.0" encoding="utf-8"?>
<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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.a.Pro.Cat">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include layout="@layout/toolbar" />
        <include layout="@layout/weight_toolbar" />

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingBottom="70dp"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin">

                <LinearLayout
                    android:id="@+id/pinned_fragment_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"></LinearLayout>

                <LinearLayout
                    android:id="@+id/fragment_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"></LinearLayout>

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

    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:onClick="Add"
        android:src="@drawable/add" />


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

工具栏XML

        <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.AppBarLayout android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/white"
    android:elevation="5dp"
    app:layout_scrollFlags="scroll|enterAlways"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <TextView
        android:id="@+id/toolbar_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="current patient's weight : "
        android:textSize="16sp" />

    <TextView
        android:id="@+id/weight_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="KG"
        android:textSize="16sp" />
    </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>

您从未在其中放置过折叠工具栏布局。。。将其放入Toolbar.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:toolbarId="@+id/toolbarDetail">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/white"
            android:elevation="5dp"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="left"
                android:text="current patient's weight : "
                android:textSize="16sp" />

            <TextView
                android:id="@+id/weight_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="left"
                android:text="KG"
                android:textSize="16sp" />
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>


此外,如果这不起作用,我会将Toolbar include语句放在CoordinatorLayout的内部,而不是LinearLayout。

您没有任何代码来实现
android.support.design.widget.CollagingToolbar布局。您只设置了一个工具栏,而没有将其包围在折叠工具栏布局中。谢谢您的回答。实际上,只有使用一个工具栏,它才能正常工作。我发现问题在于使用了两个工具栏。没有解决方法吗?我能说的就是合并两个工具栏。很好,但我想折叠/滚动其中一个,同时固定另一个。我正在尝试做完全相同的事情。你弄明白了吗@我想我没能解决这个问题。最后,我在协调器布局中使用了一个带有滚动标志的回收器视图。