你好,
我遇到了一个问题,当FloatingActionButton的可见性设置为GONE时,在打开活动时会短暂地显示出来,然后像应该的那样消失。
这个按钮在稍后的某个时间点使用,所以必须是不可见的。但是目前如果有人足够快(主要是在旧设备/Android版本上),他就可以在应该允许之前单击该按钮。
我的布局与由Android Studio创建的布局几乎相同,只是我将可见性设置为gone:
<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" android:fitsSystemWindows="true"
tools:context="com.fallenritemonk.ludus.game.GameActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_game" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_fields_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add"
android:visibility="gone" />
</android.support.design.widget.CoordinatorLayout>
content_game.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.fallenritemonk.ludus.game.GameActivity">
<GridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fieldGrid"
android:numColumns="9"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp" />
</RelativeLayout>
我不知道问题出在哪里。我尝试将它设置为INVISIBLE而不是GONE。由于我无法确定用户是否足够快地按下按钮,因此防止他这样做的唯一可能性是消除“快速上升FAB”错误。
如果需要更多信息,请随时询问!
谢谢你的帮助。