今天给大家带来一个效果比较好的而且很容易实现的控件FloatingActionButton!我们一起来对FloatingActionButton做一些基本了解吧!
FloatingActionButton简单介绍
FloatingActionButton是继承至ImageView,拥有ImageView的所有属性。
CoordinatorLayout配合FloatingActionButton实现浮动按钮。
app:layout_anchor和app:layout_anchorGravity设置FloatingActionButton位置与效果。
FloatingActionButton使用
- <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=http://blog.csdn.net/u010687392/article/details/"@mipmap/icon"
- app:backgroundTint="#30469b"
- app:borderWidth="0dp"
- app:elevation="6dp"
- app:fabSize="normal"
- app:layout_anchor="@id/coordinator_layout"
- app:layout_anchorGravity="bottom|right"
- app:pressedTranslationZ="12dp"
- app:rippleColor="#a6a6a6" />
FloatingActionButton属性解析
- app:backgroundTint - 设置背景颜色。
- app:rippleColor - 设置点击时的背景颜色。
- app:borderWidth - 该属性如果不设置0dp,那么在4.1的sdk上FAB会显示为正方形,而且在5.0以后的sdk没有阴影效果。所以设置为borderWidth="0dp"。
- app:elevation - 默认状态下阴影大小。
- app:pressedTranslationZ - 点击时的阴影大小。
- app:fabSize - 设置大小,该属性有两个值,分别为normal和mini,对应的大小分别为56dp和40dp。
- src - 设置图标,Google建议符合Design设计的该图标大小为24dp。
- app:layout_anchor - 设置锚点,即以哪个控件为参照点设置位置。
- app:layout_anchorGravity - 设置相对锚点的位置,值有 bottom、center、right、left、top等。
FloatingActionButton注意
一般情况下,FAB与Snackbar配合使用时候会出现Snackbar遮住FloatingActionButton,为了解决这个问题,我们把Snackbar.make(View view,,).show();的第一个参数View设置为CoordinatorLayout,把mCoordinatorLayout传给SnackbarSnackbar.make(mCoordinatorLayout.getRootView(), "Snackbar", Snackbar.LENGTH_SHORT).show();
本文系转载,原博客地址:http://blog.csdn.net/caihongdao123