浮动操作按钮不在右下 [英] Floating Action Button Not In Bottom Right

查看:128
本文介绍了浮动操作按钮不在右下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我的FAB不会像往常一样显示在屏幕的右下角.我在一个片段中,该片段是协调器布局(我不知道这是否是一个好习惯).

My FAB for some reason won't go to the bottom right corner of the screen as usual. I'm inside a fragment and that fragment is a coordinator layout (I don't know if this is a good practice or not).

这是布局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>

由于某种原因,FAB最终位于右上角而不是右下角.有人知道我在做什么错吗?

And for some reason the FAB ends up in the top right instead of the bottom right. Does anyone know what I'm doing wrong?

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

这是我的main_activity xml,用于显示片段的放置位置(容器" FrameLayout).

Here's my main_activity xml to show where I'm putting the fragment (The "container" FrameLayout).

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorGrey">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <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/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.AppBarLayout>

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

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/container">
        </FrameLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

推荐答案

问题即将出现,原因是android.support.v4.widget.NestedScrollView再添加一个字段android:fillViewport="true". Issue was coming as your NestedScrollView`不能扩展为匹配父级或占用可用空间.使用我的代码进行了良好的测试

The issue is coming due to android.support.v4.widget.NestedScrollView add one more field android:fillViewport="true". Issue was coming as yourNestedScrollView` was not expanding to match parent or take available space. Working fine tested with my code

<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>

这篇关于浮动操作按钮不在右下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆