![](https://img.haomeiwen.com/i1775338/c664a8bb3db77112.jpg)
引言
FloatingActionButton是Material Deisgn中的其中一个控件,继承自ImageView。
1.几种属性
属性名 | 注释 |
---|---|
app:elevation | 设置阴影 |
app:rippleColor | 扩散效果的颜色 |
app:fabSize | 设置FloatingActionButton的size |
app:useCompatPadding | 兼容padding 可用 |
2.几种常见demo
在Material Design之Snackbar一文中我们有用到过他和CoordinatorLayout、SnackBar的联合使用,下面我们看看另一种效果图:
![](https://img.haomeiwen.com/i1775338/ba8a7bfb4a4b47d7.gif)
布局文件:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gjj.gd.materialdesign_v7.fab.FabActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/ThemeOverlay.AppCompat.Dark">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/coll"
android:layout_width="match_parent"
android:layout_height="250dp"
app:contentScrim="#009585"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@mipmap/bg"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:textSize="18sp"
android:text="@string/large_text"/>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_dialog_alert"
android:layout_marginBottom="20dp"
android:layout_marginRight="15dp"
app:layout_anchor="@+id/appbarlayout"
app:layout_anchorGravity="bottom|right"
app:elevation="5dp"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_dialog_email"
android:layout_marginBottom="20dp"
android:layout_marginRight="15dp"
android:layout_gravity="bottom|right"
app:rippleColor="@android:color/darker_gray"
app:elevation="3dp"
/>
</android.support.design.widget.CoordinatorLayout>
网友评论