禁用CollapsingToolbar在滚动时折叠的功能

时间:2017-01-05 15:09:12

标签: android android-coordinatorlayout android-collapsingtoolbarlayout

我希望我的collapsingtoolbar只能在响应onclicklistener时崩溃,而不是滚动事件。我不知道如何实现这一目标。我一直在玩滚动标志,但无法提出解决方案。这就是我的布局目前的样子:

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/CalorieDagger.AppBarOverlay"
    app:expanded="false"
    app:layout_behavior="com.example.jay.caloriedagger.ui.ScrollingCalendarBehavior">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:minHeight="?attr/actionBarSize"
        app:contentScrim="?attr/colorPrimary"
        app:statusBarScrim="?attr/colorPrimaryDark"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:elevation="4dp">

        <LinearLayout
            android:id="@+id/compactcalendar_view_container"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:paddingTop="?attr/actionBarSize"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="1.0">

            <com.github.sundeepk.compactcalendarview.CompactCalendarView
                android:id="@+id/compactCalendarView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                app:compactCalendarBackgroundColor="?attr/colorPrimary"
                app:compactCalendarCurrentDayBackgroundColor="#FFC107"
                app:compactCalendarCurrentSelectedDayBackgroundColor="#BBDEFB"
                app:compactCalendarTextColor="#fff"
                app:compactCalendarTextSize="12sp" />
        </LinearLayout>

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

            <RelativeLayout
                android:id="@+id/date_picker_button"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?android:selectableItemBackground"
                android:clickable="true"
                android:orientation="vertical">

                <View
                    android:id="@+id/centerInParent"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_centerVertical="true" />

                <TextView
                    android:id="@+id/title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_above="@id/centerInParent"
                    android:ellipsize="end"
                    android:maxLines="1"
                    android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
                    android:textColor="@android:color/white" />

                <TextView
                    android:id="@+id/date_picker_text_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/centerInParent"
                    android:ellipsize="end"
                    android:maxLines="1"
                    android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle"
                    android:textColor="@android:color/white" />

                <ImageView
                    android:id="@+id/date_picker_arrow"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@id/date_picker_text_view"
                    android:layout_toRightOf="@id/date_picker_text_view"
                    app:srcCompat="@drawable/ic_arrow_drop_down"
                    tools:ignore="ContentDescription,RtlHardcoded" />
            </RelativeLayout>
        </android.support.v7.widget.Toolbar>

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

<FrameLayout
    android:id="@+id/mainContentFrame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>

0 个答案:

没有答案