Android:浮动动作按钮的定位不可预测

Android:浮动动作按钮的定位不可预测,android,xamarin.android,floating-action-button,Android,Xamarin.android,Floating Action Button,我的一些浮动操作按钮不在我想要的地方,我不明白为什么。 第一个是他们应该是怎样的(实际上有时是这样的),另外两个图像显示了他们有时的行为方式。。。我找不到这种行为的“模式” 这是布局(只有一半): 在相同的条件/代码下,有时有效,有时无效。它看起来像是Android中的一个bug。我试过Android 7.0和7.1,Xamarin.Android.Support.Compat.25.3.1。 任何有类似问题或知道原因的人?请使用詹姆斯·蒙特马诺的FAB 将nuget的james montema

我的一些浮动操作按钮不在我想要的地方,我不明白为什么。 第一个是他们应该是怎样的(实际上有时是这样的),另外两个图像显示了他们有时的行为方式。。。我找不到这种行为的“模式”

这是布局(只有一半):

在相同的条件/代码下,有时有效,有时无效。它看起来像是Android中的一个bug。我试过Android 7.0和7.1,Xamarin.Android.Support.Compat.25.3.1。
任何有类似问题或知道原因的人?

请使用詹姆斯·蒙特马诺的FAB

将nuget的james montemagno的FAB添加到您的项目中。



使用布局重力进行定位

<android.support.design.widget.FloatingActionButton
   android:id="@+id/fab"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="bottom|right"
   android:src="@drawable/ic_edit"
   android:layout_marginRight="15dp"
   android:layout_marginBottom="15dp" / >


如果更改晶圆厂定位点视图的可见性,按钮将移动。如果不想移动,请确保“锚定视图”保持相同的宽度。@AlexandreBOURETZ你认为这是因为当我隐藏列表的容器时,我将其宽度和高度设置为零?我试过了,非常感谢。欢迎告诉我它是否有效。@AlexandreBOURETZ我试过各种组合,也总是保留两个列表,每次我改变晶圆厂的可见性时,它们都会随机移动。我会更新一下我的问题。谢谢,我会尝试一下。在我尝试更新我的所有软件包之前,也许我也会尝试使用Android 7.1,只是为了了解这是否是Android fab的一个bug。有用的答案,因为你给了我一个替代方案,但我浪费了一个小时试图使它工作,我总是有问题“没有找到类”Refractored.fab.FloatingActionButton“在路径:DexPathList上”。我放弃了,这个组件已经很旧了,如果可能的话,我更愿意保留在标准上。你会得到这个错误,因为你没有将nuget中的组件包括到你的项目中。我用标准浮动操作按钮发布了另一个答案。始终使用布局重力来定位任何组件。我包括了该软件包,顺便说一下,我浪费了一个多小时来使用我不想使用的组件…它不起作用,我尝试了布局重力和/或布局重力的所有组合。该bug的行为完全不确定。我在片段生命周期中使用它的方式可能有问题。无论如何谢谢你。完全删除你的晶圆厂代码并粘贴此代码。它在我的系统上工作。可能我没有解释清楚。。。我的布局在开始和大多数时候都很有效。但是,当我在选项卡式面板中重新排列我的片段时,其中一些片段移动到了错误的位置,但只是有时。
CoordinatorLayout.LayoutParams editOrigineFabParams = (CoordinatorLayout.LayoutParams)editOrigineFab.LayoutParameters;
editOrigineFabParams.AnchorId = Resource.Id.list_attivita_edit_origini;
editOrigineFabParams.AnchorGravity = (int)(GravityFlags.Top | GravityFlags.Right | GravityFlags.End);
editOrigineFab.LayoutParameters = editOrigineFabParams;
<Refractored.Fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="16dp"
        android:src="@drawable/ic_action_content_new"
        app:app_colorNormal="@color/primary"
        app:app_colorPressed="@color/primary_pressed"
        app:app_colorRipple="@color/ripple" />
<android.support.design.widget.FloatingActionButton
   android:id="@+id/fab"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="bottom|right"
   android:src="@drawable/ic_edit"
   android:layout_marginRight="15dp"
   android:layout_marginBottom="15dp" / >