FloatingActionButton没有显示在CollapsingToolbarLayout中

时间:2018-11-08 15:09:30

标签: android android-layout android-collapsingtoolbarlayout floating-action-button

嗨,我需要在EditText中显示2个FloatingActionButtonCollapsingToolbarLayout。我已经使用this Code来显示CollapsingToolbarLayout,但是我的FloatingActionButton在Real Device(Redmi Note 4)中不可见。

XML代码

<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.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_tool_bar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:statusBarScrim="?attr/colorAccent">
<FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"
                android:layout_marginLeft="72dp"
                android:layout_marginRight="16dp"
                android:layout_marginBottom="32dp"
                android:layout_marginTop="136dp">
    -->1st textView
 </FrameLayout>
    <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/primary"
                    android:minHeight="?attr/actionBarSize"
                    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
    -->2nd TextView

                </android.support.v7.widget.Toolbar>

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


        <android.support.design.widget.FloatingActionButton
          android:id="@+id/floating_action_button"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_margin="@dimen/fab_margin"
          app:layout_anchor="@id/appbar"
          app:layout_anchorGravity="bottom|end"
          app:srcCompat="@drawable/ic_add_black_24dp" />

output layout iam getting

1 个答案:

答案 0 :(得分:0)

您粘贴的代码不是完整的代码,也没有NavigationView,因为您提供的图片显示存在{{1}(至少包含NavigationView)的DrawerLayout }}等

但是,此代码有效:

CoordinatorLayout

结果:

enter image description here

也许您在<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.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_tool_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:statusBarScrim="?attr/colorAccent"> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="72dp" android:layout_marginTop="136dp" android:layout_marginEnd="16dp" android:layout_marginBottom="32dp" app:layout_collapseMode="parallax" /> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimary" android:minHeight="?attr/actionBarSize" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:layout_collapseMode="pin" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> </android.support.v7.widget.Toolbar> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.design.widget.FloatingActionButton android:id="@+id/floating_action_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp" app:fabSize="normal" app:layout_anchor="@+id/appbar" app:layout_anchorGravity="bottom|end" app:srcCompat="@drawable/ic_settings_white_24dp" /> </android.support.design.widget.CoordinatorLayout> 中需要“ +”,或者如果该代码没有帮助,app:layout_anchor="@+id/appbar"还有一个问题。另外,请确保DrawerLayoutCoordinatorLayout的子元素。