Android浮动操作按钮未返回初始位置
如果FAB(浮动动作按钮)在蛇纹条出现之前隐藏(在坐标布局中),那么下次我显示FAB时,它将在旧位置绘制(未向下移动到原始位置)。如果当snackbar消失时晶圆厂可见,那么一切都正常工作。我是错过了什么还是一只虫子 UPD:根据要求,这里是一个最小的示例。我将把最重要的部分放在这里,可以找到一个完整的工作示例 这只是Android模板活动项目中的一个稍加修改的示例Android浮动操作按钮未返回初始位置,android,floating-action-button,android-snackbar,Android,Floating Action Button,Android Snackbar,如果FAB(浮动动作按钮)在蛇纹条出现之前隐藏(在坐标布局中),那么下次我显示FAB时,它将在旧位置绘制(未向下移动到原始位置)。如果当snackbar消失时晶圆厂可见,那么一切都正常工作。我是错过了什么还是一只虫子 UPD:根据要求,这里是一个最小的示例。我将把最重要的部分放在这里,可以找到一个完整的工作示例 这只是Android模板活动项目中的一个稍加修改的示例 活动\u main.xml: <?xml version="1.0" encoding="utf-8"?> <a
活动\u main.xml
:
<?xml version="1.0" encoding="utf-8"?>
<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="coordination.fab.snackbar.test.testfabsnackbar.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
本质上,我只是确保当snackbar隐藏时,动作按钮保持隐藏状态
如果你需要更多的信息,请告诉我
UPD2如果你无意中发现了这条线索并且不喜欢它,请告诉我我可以改进什么。我真的很想知道如何克服这个问题
UPD3在Android bug tracker中创建的问题被合并为一个问题,应该在下一个版本中修复直到看到你的帖子,我才意识到我有这个问题,但它也发生在我的应用程序中 通过查看,我看到他们根据Snackbar设置了晶圆厂的平移,但前提是晶圆厂可见。如果FAB不可见,则平移Y不会更改,因此根据其隐藏和显示的时间,它可能会最终卡在错误的位置 我刚才所做的,并且似乎有效的,是在适当的情况下自己重新设置翻译 将snackbar声明为类级变量,以便检查其状态
Snackbar snack;
然后,在需要时使用此工具制作snackbar:
snack.make(...etc...).show();
然后,当我们调用fab.show()
方法时,我们可以检查snack
的状态并自行重置translationY
if(snack != null){
if(!snack.isShown()) {
//if the snackbar is not shown, make sure the fab is at the
//original location
fab.setTranslationY(0.0f);
}
}
fab.show();
无论出于何种原因,如果晶圆厂的正确翻译不是0.0,您可能希望使用FAB.getTranslationY来保存正确的值,并在需要重置时使用该值。这已作为发行版的一部分修复,现在已修复。能否向我们展示隐藏晶圆厂的代码?也给我们看一下你的布局。@DanielNugent你看。告诉我是否还有什么不清楚的地方。@gj_u我已经在我的问题hmmm的UPD部分的一个最小示例中演示了布局。我不知道它是开源的。那很酷。然而,这种行为对我来说似乎很奇怪。我想知道如果没有看到晶圆厂,不更新位置的决定背后有什么原因。无论如何,这解决了我的问题,尽管这不是地球上最好的解决方案。谢谢我已经为此提交了一份安卓问题跟踪报告。
if(snack != null){
if(!snack.isShown()) {
//if the snackbar is not shown, make sure the fab is at the
//original location
fab.setTranslationY(0.0f);
}
}
fab.show();