Dan*_*ico 5 android android-fragments material-design floating-action-button android-coordinatorlayout
我使用MaterialDrawer并根据所选项目MainDrawerActivity替换容器 内的每个片段FrameLayout,但我想添加一个与之交互的 FAB(仅用于此片段),CoordinatorLayout以便它可以处理很酷的动画。
主抽屉布局:
<?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: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:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:minHeight="?actionBarSize"
android:theme="@style/Toolbar"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我如何替换每个片段:
try {
supportFragmentManager.beginTransaction().replace(R.id.container, FeedFragment()).commit()
} catch (e: IllegalStateException) {
Timber.i(e, "Fragment is still there.")
}
Run Code Online (Sandbox Code Playgroud)
片段布局:
<FrameLayout 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">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/feed_item" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginRight="@dimen/spacing_medium"
android:elevation="@dimen/elevation_little"
app:fabSize="normal"
app:layout_anchor="@+id/container"
app:layout_anchorGravity="bottom|right"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:srcCompat="@drawable/ic_add_white_18dp" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
但结果是 FAB 按钮在底部栏后面:
我正在尝试设置协调器布局属性(layout_anchor和那些)以匹配主布局 ID,但它不起作用......为什么?