FloatingActionButton始终可见 [英] FloatingActionButton always visible

查看:355
本文介绍了FloatingActionButton始终可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我越来越熟悉新support.design库,我面临的FloatingActionButton这个问题。我试图以编程方式隐藏它,但按钮保持始终可见。

I am getting familiar with the new support.design library and I'm facing this issue with the FloatingActionButton. I'm trying to hide it programmatically, but the button stay always visible.

我有应用程序的感觉:layout_anchor =@ ID / appbar必须覆盖按钮的可见性。

I have the feeling that app:layout_anchor="@id/appbar" must override the visibility of the button.

JAVA:

@InjectView(R.id.search_fab)
FloatingActionButton search_fab;

[...]

search_fab.setVisibility(View.GONE);

XML:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true">

    <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="?attr/colorPrimary"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp"
        android:theme="@style/ToolBarStyle"
        >

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_gravity="center"
            android:layout_height="210dp"
            android:id="@+id/top_sales_product_recycler_view"
            />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin"
            android:theme="@style/ToolBarStyle"
            />

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


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

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/category_recycler_view"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    />

<android.support.design.widget.FloatingActionButton
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    app:layout_anchor="@id/appbar"
    app:layout_anchorGravity="bottom|right|end"
    android:src="@drawable/abc_ic_search_api_mtrl_alpha"
    android:layout_margin="@dimen/fab_margin"
    android:id="@+id/search_fab"
    app:borderWidth="1dp"
    />

推荐答案

要摆脱锚可以使用的:

CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setAnchorId(View.NO_ID);
fab.setLayoutParams(p);

据我所知,有一个锚确实真的像你说的,影响隐藏按钮的可能性,所以调用此能见度变化应该工作了。

As far as I know, having an anchor does really, as you say, affect the possibility of hiding the button, so calling this before the visibility change should work.

这篇关于FloatingActionButton始终可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆