您的位置:首页 > 移动开发 > Android开发

Android第三方开源FloatingActionButton(com.getbase.floatingactionbutton)【1】

2015-12-03 21:44 393 查看

Android第三方开源FloatingActionButton(com.getbase.floatingactionbutton)【1】
由于FloatingActionButton在用户体验上取得了很好的效果,除了Android谷歌官方给出的原生FloatingActionButton之外,第三方也有很多FloatingActionButton的实现解决方案,比如github上的另外一个第三方开源FloatingActionButton项目主页:https://github.com/futuresimple/android-floating-action-button

该FloatingActionButton项目除了实现向Android谷歌官方实现的FloatingActionButton那样的效果外,还有一种特殊的动画效果,比如当用户点击一个FloatingActionButton时候,会弹出一长串FloatingActionButton等等,随后的文章中分节介绍如何具体使用。

先根据该开源FloatingActionButton项目写一个简单FloatingActionButton。

写一个简单的布局文件即可实现:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="zhangphil.fab.MainActivity" >

<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/pink_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_icon="@drawable/ic_launcher"
fab:fab_colorNormal="@color/pink"
fab:fab_colorPressed="@color/pink_pressed"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"/>

</RelativeLayout>


其颜色值在其项目的示例代码包中有定义(sample下的Activity中res/values/colors.xml):

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black_semi_transparent">#B2000000</color>
<color name="background">#e5e5e5</color>
<color name="half_black">#808080</color>
<color name="white">#fafafa</color>
<color name="white_pressed">#f1f1f1</color>
<color name="pink">#e91e63</color>
<color name="pink_pressed">#ec407a</color>
<color name="blue_semi_transparent">#805677fc</color>
<color name="blue_semi_transparent_pressed">#80738ffe</color>
</resources>


本例代码运行结果如图所示:



附录参考文章:

【1】《Android Material Design的FloatingActionButton,Snackbar和CoordinatorLayout》链接地址:http://blog.csdn.net/zhangphil/article/details/48861371

【2】《Android第三方FloatingActionButton:伴随ListView、RecyclerView、ScrollView滚动滑入滑出》链接地址:http://blog.csdn.net/zhangphil/article/details/50135707
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: