记录一下项目近期遇到的跟FloatingButton相关的一个小问题。 背景:须要画一个固定在某个位置,不随其余控件移动而移动的按钮。android
设计稿:bash
切图:app
<android.support.design.widget.FloatingActionButton
android:id="@+id/iv_join"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/and_blue_448bf5"
android:scaleType="fitEnd"
android:src="@mipmap/icon_join"
app:fabSize="normal"
app:layout_constraintBottom_toBottomOf="@+id/vp_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/vp_content" />
复制代码
第二阶段: 介于对FloatingButton的不熟悉,上网了解了一下它。发现我并无办法找到使他变成各类形状的办法,因此最后只能说应该是它就是长成圆形的。字体
第三阶段: 使图片和按钮比例协调!这个的实现网上搜获得不少答案,最多的一种是说图片要24dp24dp,加android:scaleType=”center”。也有人说, app:fabSize="normal" android:scaleType=”center” 同时存在,就能够打破图片的尺寸限制。可是我都试了,打破限制的没有,设置了24dp24dp以后,比例确实和谐了,可是由于分辨率的问题,字体显得很模糊。(也多是我不会用ps调...) 代码仍是跟上面的同样,效果:动画
第四阶段: 反正里面的箭头也不明显,不如直接在里面写字好了。试了一下。FloatingButton没有text属性。很天然地我想到了加个textview。 听起来好像没毛病,但是这个textview死活就是藏在FloatingButton下面不上来。通过几番百度,终于在stackflow找到了答案,在textview加上evalation属性。完美!spa
代码:设计
<FrameLayout
android:layout_width="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="wrap_content">
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/and_blue_448bf5"
app:borderWidth="0dp"
android:elevation="0dp"
app:fabSize="normal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_gravity="center"
android:text="入驻"
android:textSize="@dimen/and_24sp"
android:elevation="7dp"/>
</FrameLayout>
复制代码
效果:code
第五阶段: 领导以为仍是有点丑,因此我又改为了酱紫。这个实现很容易,就很少说啦~orm
代码:cdn
<Button
android:id="@+id/fab"
android:layout_width="50dp"
android:layout_height="@dimen/and_30dp"
android:elevation="0dp"
android:text="入驻"
android:gravity="center"
android:textColor="@color/white"
android:background="@drawable/rect_448bf5_radius_5"
app:layout_constraintBottom_toBottomOf="@+id/vp_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/vp_content" />
复制代码
效果:
一、app:borderWidth=""------------------边框宽度,一般设置为0 ,用于解决Android 5.X设备上阴影没法正常显示的问题。
二、app:backgroundTint=""---------------设置按钮的背景颜色或者背景图片,不设置,默认使用theme中colorAccent的颜色。
三、app:rippleColor=""--------------------点击的边缘阴影颜色。
四、app:elevation=""----------------------边缘阴影的宽度。
五、 app:fabSize=“”----------------------设置按钮大小。
昨儿个偶然得知了一个叫CircularReveal的家伙,能够作一下点击按钮以后跳转activity的动画。回头弄完再撸篇文章,等我~
- 咱们正在招募小伙伴,有兴趣的小伙伴能够把简历发到 app@talkmoney.cn,备注:来自掘金社区
- 详情能够戳这里--> 广州芦苇信息科技