FAB没有正确锚定 - Android设计支持库

时间:2015-07-04 04:53:15

标签: java android xml android-support-library androiddesignsupport

目前我有一个布局,我希望将FAB置于布局的底部,但不是固定在底部,而是通过导航按钮,只有在向下滚动Recyclerview后才会锚定。

我的布局如下:

activity_main.xml中

<android.support.v4.widget.DrawerLayout
    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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/appbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="?attr/actionBarSize"
                    android:background="@color/primary"
                    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:layout_scrollFlags="scroll|enterAlways"/>

                <android.support.design.widget.TabLayout
                    android:id="@+id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:tabTextColor="@android:color/white"
                    app:tabSelectedTextColor="@android:color/white"
                    app:tabGravity="center"
                    android:theme="@style/Material"
                    app:tabIndicatorColor="@color/accent"
                    app:tabIndicatorHeight="@dimen/tabs_indicator_height"
                    app:tabMode="fixed"
                    android:background="@color/primary"
                    android:minHeight="?attr/actionBarSize"/>
            </android.support.design.widget.AppBarLayout>

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipChildren="true"
                android:fitsSystemWindows="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

    </LinearLayout>


    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         If you're not building against API 17 or higher, use
         android:layout_gravity="left" instead. -->
    <!-- The drawer is given a fixed width in dp and extends the full height of
         the container. -->
    <android.support.design.widget.NavigationView
        android:id="@+id/drawer"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/menu_drawer"/>

</android.support.v4.widget.DrawerLayout>

fragment_event.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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.support.v7.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <com.melnykov.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:layout_gravity="bottom|center"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|center"
        app:fab_colorNormal="@color/accent"/>

</FrameLayout>

片段在viewpager中,这就是: Broken! Scroll up it's fine

如果我让FAB成为协调员布局的孩子,它可以正常工作...... enter image description here

0 个答案:

没有答案