Android 浮动操作按钮不在右下角

Android 浮动操作按钮不在右下角,android,android-coordinatorlayout,gravity,floating-action-button,Android,Android Coordinatorlayout,Gravity,Floating Action Button,由于某种原因,我的晶圆厂不会像往常一样出现在屏幕的右下角。我在一个片段中,该片段是一个协调器布局(我不知道这是否是一个好的实践) 以下是布局xml代码: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xm

由于某种原因,我的晶圆厂不会像往常一样出现在屏幕的右下角。我在一个片段中,该片段是一个协调器布局(我不知道这是否是一个好的实践)

以下是布局xml代码:

<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"
    tools:context="com.gigstudios.polls.fragment.MyPollsFragment">

    <LinearLayout
        android:id="@+id/linear_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </android.support.v7.widget.RecyclerView>

    </LinearLayout>

    <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="@drawable/ic_add_white_36dp"
        app:fabSize="normal"
        app:layout_anchor="@id/linear_layout"
        app:layout_anchorGravity="bottom|right|end" />

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

由于某些原因,晶圆厂最终位于右上角,而不是右下角。有人知道我做错了什么吗

顺便说一句,xml预览总是在右下角显示fab按钮,但当我在手机上运行它时,它却在右上角。

编辑:这是我的主要活动xml,用于显示我将片段放在何处(“容器”框架布局)


删除行

app:layout_anchor="@id/linear_layout"
app:layout_anchorGravity="bottom|right|end"
在您的
浮动操作按钮上
。它们没有做任何事情(因为您锚定到一个填充整个
协调布局的视图)。这将导致尊重您的
布局_重力
,并且您的
浮动操作按钮
将放置在
坐标布局的右下角
删除行

app:layout_anchor="@id/linear_layout"
app:layout_anchorGravity="bottom|right|end"

在您的
浮动操作按钮上
。它们没有做任何事情(因为您锚定到一个填充整个
协调布局的视图)。这将使您的
布局受到尊重,并且您的
浮动操作按钮将被放置在
坐标布局的右下角
问题是由于
android.support.v4.widget.NestedScrollView
添加一个字段
android:fillViewport=“true”。问题是由于您的
NestedScrollView`未扩展以匹配父级或占用可用空间。使用我的代码测试工作正常

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:fillViewport="true"
    android:layout_marginTop="?attr/actionBarSize">
</android.support.v4.widget.NestedScrollView>

这个问题是由于
android.support.v4.widget.NestedScrollView
再添加一个字段
android:fillViewport=“true”引起的。问题是由于您的
NestedScrollView`未扩展以匹配父级或占用可用空间。使用我的代码测试工作正常

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:fillViewport="true"
    android:layout_marginTop="?attr/actionBarSize">
</android.support.v4.widget.NestedScrollView>


从您的浮动操作按钮
xml
中删除
android:layout|gravity=“bottom | end”
,它会工作的

从您的浮动操作按钮
xml
中删除
android:layout|gravity=“bottom | end”
,它会工作的

只需添加android:layout|gravity=“bottom,删除所有其他重力相关标签添加额外框架布局查看我的答案如果有用只需添加android:layout_gravity=“bottom | end”,删除所有其他重力相关标签添加额外框架布局查看我的答案如果有用我这样做了,但仍然不起作用。顺便说一句,xml预览总是在右下角显示fab按钮,但当我在手机上运行它时,它却在右上角。你的
MyPollsFragment
你在屏幕上使用的是这种布局吗?或者在您放置它的布局中,它是否有
wrap_内容
作为其高度?是的,它会填充屏幕。我将添加我的主要活动xml,以显示我将片段放在何处。我这样做了,但仍然不起作用。顺便说一句,xml预览总是在右下角显示fab按钮,但当我在手机上运行它时,它却在右上角。你的
MyPollsFragment
你在屏幕上使用的是这种布局吗?或者在您放置它的布局中,它是否有
wrap_内容
作为其高度?是的,它会填充屏幕。我将添加我的主要活动xml,以显示我将片段放在何处。请检查上面编辑的答案,它对我适用请检查上面编辑的答案,它对我适用