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

使用FloatingActionButton无法浮现在ListView的原因

2016-02-12 23:28 429 查看
最近在项目中设计要求在主界面添加一个浮动按钮,第一时间就想到过最近比较火的FloatingActionButton,这里放上作者的github网址:点击打开链接

        然后在网上开始查资料..第一时间没有去作者的github的网址去查资料..教训啊..其实最好还是去作者的网站去查询如何使用,不过很遗憾当时并不知道这个design的作者.所以去网上搜索了一下.后来找到material design的一些用法..然而有一个问题没有解决..就是FloatingActionButton没办法浮动在Listview的上方,那还叫什么FLoating对不对!于是各种想办法解决..话说回来,没梯子真的挺累的,百度找这种问题没有办法...stackOverFlow还是挺有用的,然而还是没有解决问题...

最后找到作者的github网址,然后反复查看了好久~~注意到作者使用的是Framelayout而我是LinearLayout..严重怀疑是FrameLayout的缘故.然后搜了一下Framelayout毕竟学太久给忘了= =.然后知道Framelayout可以重复覆盖..然后问题就迎刃而解了..就是要把ListView和FloatingActionButton防止在同一个FrameLayout中,然后ListView的height属性不能设置为0.不然下面一片黑(因为是0就什么都没有,一片黑啊)...

放上改过之后正确的代码 :

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/alarms_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:descendantFocusability="blocksDescendants"
android:divider="#bbbbbb"
android:dividerHeight="1dp" />
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="0dp"
android:src="@drawable/sign_add"
fab:fab_type = "mini"
fab:fab_colorNormal="@color/primary"
fab:fab_colorPressed="@color/primary_pressed"
fab:fab_colorRipple="@color/ripple"
/>
</FrameLayout>这里面的很多属性是不必要的....是我从自己的项目之中截取出来的..所以只要注意加上每个view的默认属性和上面所提到的一些细节就能够解决问题啦.
其实还是太弱= =,竟然一开始没看懂实现的细节!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息