FloatingActionButton setVisibility()不起作用 [英] FloatingActionButton setVisibility() not working
本文介绍了FloatingActionButton setVisibility()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法隐藏我的FloatingActionButton
.这是我的代码:
I can't hide my FloatingActionButton
. Here is my code:
XML:
<CoordinatorLayout>
<AppBarLayout android:id="@+id/appbar">
<CollapsingToolbarLayout>
<ImageView/>
<android.support.v7.widget.Toolbar />
</CollapsingToolbarLayout>
</AppBarLayout>
<NestedScrollView />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"/>
</CoordinatorLayout>
我打电话:
fab.clearAnimation();
fab.setVisibility(View.GONE);
我正试图隐藏FAB,但如果FAB位于CoordinatorLayout
中,则setVisibility
+ clearAnimation
似乎不起作用.
I'm trying to hide the FAB, but it seems that setVisibility
+ clearAnimation
does not work if the FAB is in a CoordinatorLayout
.
即使我调用fab.clearAnimation
,动画仍会触发.谁能帮我吗?
Even if I call fab.clearAnimation
, the animation is still triggered. Can anyone help me?
推荐答案
如果您的问题是动画,则可以尝试使FAB Behavior
无效.至于可见性,您应该将在布局中设置的锚定为空:
If your issue is the animation, you could try invalidating the FAB Behavior
. As for the visibility, you should null the anchor you have set in your layout:
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setBehavior(null); //should disable default animations
p.setAnchorId(View.NO_ID); //should let you set visibility
fab.setLayoutParams(p);
fab.setVisibility(View.GONE); // View.INVISIBLE might also be worth trying
//to bring things back to normal state
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setBehavior(new FloatingActionButton.Behavior());
p.setAnchorId(R.id.appbar);
fab.setLayoutParams(p);
这篇关于FloatingActionButton setVisibility()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文