CoordinatorLayout,FAB和容器布局冲突 [英] CoordinatorLayout, FAB and container layout conflict
问题描述
我有一个带有container layout
的抽屉的主要活动,在其中用FragmentManager
替换每个片段.
I have a main activity with a drawer that have a container layout
where I replace each fragment with FragmentManager
.
我想将FAB添加到我的一个子片段中,该子片段可以滚动显示隐藏/显示,但是我不确定自己在做什么错并得到:
I want to add a FAB to one of my child fragments that hide/show on scroll but Im not sure what Im doing wrong and get:
布局:
<?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.FloatingActionButton
style="@style/Widget.Design.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginRight="@dimen/spacing_medium"
android:elevation="@dimen/elevation_little"
app:fabSize="normal"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:srcCompat="@drawable/ic_add_white_18dp" />
</android.support.design.widget.CoordinatorLayout>
推荐答案
-
看起来像
CoordinatorLayout
不能处理不是直接子级" 的子级视图的行为.
Looks like
CoordinatorLayout
cant handle behaviour of children views that are not "direct children".
您需要在fab视图中添加app:layout_anchorGravity="bottom|right|end"
和android:layout_gravity="end|bottom"
.
You need to add a app:layout_anchorGravity="bottom|right|end"
and android:layout_gravity="end|bottom"
in your fab view.
例如:
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_feeds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_plus_white"
app:layout_anchorGravity="bottom|right|end"/>
这篇关于CoordinatorLayout,FAB和容器布局冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!