CoordinatorLayout中的第三方FloatingActionButton库

Tri*_*ley 7 android android-support-library floating-action-button android-coordinatorlayout

我试图使用futuresimple的FloatingActionButton来使用FloatingActionMenu内部,CoordinatorLayout所以当我显示SnackbarFAB将向上移动而不被隐藏时Snackbar.在FloatingActionMenu完美的工作,虽然我已经注意到了第三方库没有内部的工作CoordinatorLayout.

当我使用来自Google的支持库FAB时CoordinatorLayout,虽然FutureSimple的库不是,但它正在按预期工作.(它被隐藏了Snackbar).

如何使第三方图书馆与CoordinatorLayout

fragment_comic.xml

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:text="@string/default_title"
    android:textAppearance="?android:textAppearanceLarge"
    android:layout_centerHorizontal="true" />

<TextView
    android:id="@+id/alt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/title"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:fadeScrollbars="false"
    android:gravity="center"
    android:maxLines="4"
    android:textColor="@color/black"
    android:paddingBottom="13dp"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:scrollbars="vertical"
    android:text="@string/default_alt"
    android:textAppearance="?android:textAppearanceMedium" />

<ImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/alt"
    android:adjustViewBounds="false"
    android:layout_marginBottom="10dp"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:scaleType="fitCenter" />


</RelativeLayout>

<com.getbase.floatingactionbutton.FloatingActionsMenu
    android:id="@+id/famMain"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    fab:fab_addButtonColorNormal="@color/material_orange"
    fab:fab_addButtonSize="normal"
    fab:fab_addButtonStrokeVisible="true"
    fab:fab_expandDirection="up"
    android:layout_gravity="bottom|end">

<com.getbase.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab_random"
    android:src="@drawable/ic_random"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    fab:fab_colorNormal="@color/material_orange"
    fab:fab_size="mini"/>

<com.getbase.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab_download"
    android:src="@drawable/ic_download"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    fab:fab_colorNormal="@color/material_orange"
    fab:fab_size="mini"/>

<com.getbase.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab_browser"
    android:src="@drawable/ic_open_browser"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    fab:fab_colorNormal="@color/material_orange"
    fab:fab_size="mini"/>

</com.getbase.floatingactionbutton.FloatingActionsMenu>
Run Code Online (Sandbox Code Playgroud)

然后在我的Java类中,我启动了我的FloatingActionsMenu

FloatingActionsMenu famView = (FloatingActionsMenu) getActivity().findViewById(R.id.famMain);
Run Code Online (Sandbox Code Playgroud)

然后我把它设置到我的小吃吧

Snackbar.make(famView, "Hover text copied to clipboard", Snackbar.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)

Ada*_*331 9

Snackbar覆盖FloatingActionMenu的原因是因为您将其设置为Snackbar的视图:

Snackbar.make(famView, "Hover text copied to clipboard", Snackbar.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)

你真正需要做的是CoordinatorLayout在布局的底部添加一个用于显示Snackbar的a.您可以以LinearLayout方式设置它,使其显示在其他所有内容之下.以下是XML的编辑版本:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.CoordinatorLayout
        xmlns:fab="http://schemas.android.com/apk/res-auto"
        android:id="@+id/coordinatorLayout"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="1">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:text="Test"
                android:textAppearance="?android:textAppearanceLarge"
                android:layout_centerHorizontal="true" />

            <TextView
                android:id="@+id/alt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/title"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center_horizontal"
                android:fadeScrollbars="false"
                android:gravity="center"
                android:maxLines="4"
                android:textColor="@android:color/black"
                android:paddingBottom="13dp"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:scrollbars="vertical"
                android:text="Test Alt"
                android:textAppearance="?android:textAppearanceMedium" />

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/alt"
                android:adjustViewBounds="false"
                android:layout_marginBottom="10dp"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:scaleType="fitCenter" />


        </RelativeLayout>

        <com.getbase.floatingactionbutton.FloatingActionsMenu
            android:id="@+id/famMain"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_addButtonColorNormal="@android:color/black"
            fab:fab_addButtonSize="normal"
            fab:fab_addButtonStrokeVisible="true"
            fab:fab_expandDirection="up"
            android:layout_gravity="bottom|end">

            <com.getbase.floatingactionbutton.FloatingActionButton
                android:id="@+id/fab_random"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@android:color/black"
                fab:fab_size="mini"/>

            <com.getbase.floatingactionbutton.FloatingActionButton
                android:id="@+id/fab_download"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@android:color/black"
                fab:fab_size="mini"/>

            <com.getbase.floatingactionbutton.FloatingActionButton
                android:id="@+id/fab_browser"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_colorNormal="@android:color/black"
                fab:fab_size="mini"/>

        </com.getbase.floatingactionbutton.FloatingActionsMenu>

        <android.support.design.widget.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/testFAB"
            android:layout_gravity="bottom|start"/>

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

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/snackbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

然后,您可以像这样获得小吃店视图:

CoordinatorLayout snackbar = (CoordinatorLayout) findViewById(R.id.snackbar);
Run Code Online (Sandbox Code Playgroud)

并使它像这样:

Snackbar.make(snackbar, "Hover text copied to clipboard", Snackbar.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)