将浮动操作按钮固定到工具栏/操作栏

时间:2015-10-08 10:59:35

标签: android floating-action-button android-collapsingtoolbarlayout coordinator-layout nestedscrollview

我有一个带有CollapsingToolbarLayout和NestedScrollView以及FloatingActionButton的CoordinatorLayout。在CollapsingToolbarLayout中有一个ImageView,其layout_collapseMode设置为parallax。 FloatingActionButton固定为CollapsingToolbarLayout。当该布局折叠或向上滚动时,图像被隐藏,甚至是FloatingActionButton。我希望在图像消失后可以看到FloatingActionButton。

这是布局代码:

<?xml version="1.0" encoding="utf-8"?>

<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/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:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/custom_color_2"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp" >

        <com.eventizon.widgets.SquareImageView
            android:id="@+id/imageViewEvent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_collapseMode="parallax"
            android:adjustViewBounds="true"
            android:fitsSystemWindows="true"
            android:scaleType="fitXY" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            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/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:clipToPadding="false" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            app:cardElevation="@dimen/spacing_medium"
            app:cardUseCompatPadding="true" >

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

                <TextView
                    android:id="@+id/textViewEventName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/spacing_large"
                    android:layout_marginRight="@dimen/spacing_large"
                    android:layout_marginTop="@dimen/spacing_large"
                    android:textAppearance="@style/TextAppearance.AppCompat.Headline" />

                <TextView
                    android:id="@+id/textViewEventDate"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/spacing_large"
                    android:layout_marginRight="@dimen/spacing_large"
                    android:layout_marginTop="@dimen/spacing_large"
                    android:text="sun, oct 4 - mon, oct 12"
                    android:textAllCaps="true"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

                <TextView
                    android:id="@+id/textViewEventOrganizer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/spacing_large"
                    android:layout_marginRight="@dimen/spacing_large"
                    android:layout_marginTop="@dimen/spacing_large"
                    android:text="By - Pritam Kadam"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

                <TextView
                    android:id="@+id/textViewEventDescription"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/spacing_large"
                    android:layout_marginRight="@dimen/spacing_large"
                    android:layout_marginTop="@dimen/spacing_large"
                    android:text="@string/lorem_ipsum"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

                <fragment
                    android:id="@+id/fragmentGoogleMap"
                    android:name="com.google.android.gms.maps.SupportMapFragment"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/spacing_large" />
            </LinearLayout>
        </android.support.v7.widget.CardView>
    </FrameLayout>
</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/floatingActionButtonOptions"
    style="@style/FabStyle"
    app:layout_anchor="@id/collapsing_toolbar"
    app:layout_anchorGravity="bottom|right|end" />

1 个答案:

答案 0 :(得分:0)

{{1}}

这只是一个提示,你可能要尝试其他事件监听器。