【问题标题】:Bring to front FAB on Android 4.4 or lower在 Android 4.4 或更低版本上将 FAB 置于前端
【发布时间】:2015-09-10 21:15:44
【问题描述】:

mi 问题是fab_bar 按钮放在RecyclerView 后面。这只发生在 Android 4.4 或更低版本中,在最新的 Android 版本中我没有任何问题。

我没有足够的声誉来发布图片,所以我留下了链接:http://i.stack.imgur.com/N5hYd.png

有什么解决办法或者是bug吗?

<?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"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:fitsSystemWindows="true"
        android:layout_height="@dimen/detail_backdrop_height"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            android:fitsSystemWindows="true"
            android:elevation="@dimen/toolbar_shadow_elevation">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />

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

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

    <android.support.design.widget.FloatingActionButton
        android:layout_height="wrap_content"
        android:id="@+id/fab_bar"
        android:layout_width="wrap_content"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|right|end"
        android:src="@drawable/ic_action_edit_light"
        android:layout_margin="@dimen/fab_margin"
        android:clickable="true"
        android:elevation="@dimen/fab_bar_shadow_elevation"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_atrib_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

【问题讨论】:

    标签: android android-layout android-recyclerview android-design-library


    【解决方案1】:

    试试这个:

    <?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"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
    
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:fitsSystemWindows="true"
            android:layout_height="@dimen/detail_backdrop_height"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:contentScrim="?attr/colorPrimary"
                android:fitsSystemWindows="true"
                android:elevation="@dimen/toolbar_shadow_elevation">
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:layout_collapseMode="pin" />
    
            </android.support.design.widget.CollapsingToolbarLayout>
    
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_atrib_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
        <android.support.design.widget.FloatingActionButton
            android:layout_height="wrap_content"
            android:id="@+id/fab_bar"
            android:layout_width="wrap_content"
            app:layout_anchor="@id/appbar"
            app:layout_anchorGravity="bottom|right|end"
            android:src="@drawable/ic_action_edit_light"
            android:layout_margin="@dimen/fab_margin"
            android:clickable="true"
            android:elevation="@dimen/fab_bar_shadow_elevation"/>
    
    </android.support.design.widget.CoordinatorLayout>
    

    在您的代码中,FAB 位于 RecyclerView 之前,因此 RecyclerView 覆盖 FAB

    【讨论】:

    • 非常感谢!我花了几天时间思考这个废话。我认为声明顺序在布局中并不重要...
    猜你喜欢
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多