Android 如何制作FloatingActionButton“;破边;
我所说的“突破边缘”是指。当晶圆厂位于两个相邻元件之间时,它会“断开一条边” 我希望我的工厂位于工具栏和内容视图之间。但现在它完全出现在内容视图的顶部: 我的晶圆厂定位在工具栏上。代码如下:Android 如何制作FloatingActionButton“;破边;,android,android-layout,Android,Android Layout,我所说的“突破边缘”是指。当晶圆厂位于两个相邻元件之间时,它会“断开一条边” 我希望我的工厂位于工具栏和内容视图之间。但现在它完全出现在内容视图的顶部: 我的晶圆厂定位在工具栏上。代码如下: <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:t
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/toolbar"
app:layout_anchorGravity="bottom|right|end"
android:src="@android:drawable/ic_dialog_email" />
应该这样做。将晶圆厂锚定到工具栏,然后将锚定重力设置为bottom | right | end
我做错了什么???您需要一个协调人或布局,如下所示:
<?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"
xmlns:card="http://schemas.android.com/tools"
android:id="@+id/rootLayout"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="380dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<android.support.v7.widget.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>
<!-- ListView or NestedScrollView or RecyclerView etc.. -->
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:layout_anchor="@+id/appbar"
app:elevation="6dp"
app:borderWidth="0dp"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
您应该将FAB
锚定到AppBarLayout
而不是工具栏
。但出于某种原因,只有当AppBarLayout
的高度超过ActionBar
高度的两倍时,锚定才会起作用。最终的代码是这样的
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="168dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="@android:drawable/ic_dialog_email"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end" />
折叠工具栏布局的目的是什么
?如果你想让你的工具栏像锚定工具栏上的FAB一样扩展。那么我应该如何实现预期效果?这里的公认答案对我来说很有用:如果你想用AppBarLayout实现这一点,请检查我的答案。这对我不起作用,我完全复制了它。哇,这起作用了。为什么需要为AppBarLayout
指定静态高度?这会给我以后带来问题。它不是静态高度,它可以是ActionBar高度的两倍以上。FAB会自动隐藏任何小于它的内容。如果您想将AppBarLayout
的高度设置为wrap\u content
,作为一种难看的攻击,您可以将AppBarLayout
的minHeight
设置为1dp
。