記錄一下項(xiàng)目近期遇到的跟FloatingButton相關(guān)的一個(gè)小問題。
背景:需要畫一個(gè)固定在某個(gè)位置,不隨其他控件移動(dòng)而移動(dòng)的按鈕。
設(shè)計(jì)稿:
第一階段:
拿到藍(lán)湖的切圖俯逾,發(fā)現(xiàn)不僅有白邊還有很大一部分的透明背景。
直接在FloatingButton設(shè)置backgroundTint后圖片顯得很小舅逸,一點(diǎn)也不美觀桌肴。而且形狀是圓形的。
切圖:
作為FloatingButton背景:
代碼:
<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" />
第二階段:
介于對(duì)FloatingButton的不熟悉琉历,上網(wǎng)了解了一下它识脆。發(fā)現(xiàn)我并沒有辦法找到使他變成各種形狀的辦法,所以最后只能說應(yīng)該是它就是長成圓形的善已。
第三階段:
使圖片和按鈕比例協(xié)調(diào)灼捂!這個(gè)的實(shí)現(xiàn)網(wǎng)上搜得到很多答案,最多的一種是說圖片要24dp24dp换团,加android:scaleType=”center”悉稠。也有人說, app:fabSize="normal" android:scaleType=”center” 同時(shí)存在艘包,就可以打破圖片的尺寸限制的猛。但是我都試了耀盗,打破限制的沒有,設(shè)置了24dp24dp之后卦尊,比例確實(shí)和諧了叛拷,但是因?yàn)榉直媛实膯栴},字體顯得很模糊岂却。(也可能是我不會(huì)用ps調(diào)...)
代碼還是跟上面的一樣忿薇,效果:
第四階段:
反正里面的箭頭也不明顯,不如直接在里面寫字好了躏哩。試了一下署浩。FloatingButton沒有text屬性。很自然地我想到了加個(gè)textview扫尺。
聽起來好像沒毛病筋栋,可是這個(gè)textview死活就是藏在FloatingButton下面不上來。經(jīng)過幾番百度正驻,終于在stackflow找到了答案弊攘,在textview加上evalation屬性。完美姑曙!
代碼:
<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>
效果:
第五階段:
領(lǐng)導(dǎo)覺得還是有點(diǎn)丑襟交,所以我又改成了醬紫。這個(gè)實(shí)現(xiàn)很容易渣磷,就不多說啦~
代碼:
<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" />
效果:
在這貼一下FloatingButton的幾個(gè)屬性:
1、app:borderWidth=""------------------邊框?qū)挾仁谑荩ǔTO(shè)置為0 醋界,用于解決Android 5.X設(shè)備上陰影無法正常顯示的問題。
2提完、app:backgroundTint=""---------------設(shè)置按鈕的背景顏色或者背景圖片形纺,不設(shè)置,默認(rèn)使用theme中colorAccent的顏色徒欣。
3逐样、app:rippleColor=""--------------------點(diǎn)擊的邊緣陰影顏色。
4打肝、app:elevation=""----------------------邊緣陰影的寬度脂新。
5、 app:fabSize=“”----------------------設(shè)置按鈕大小粗梭。
昨兒個(gè)偶然得知了一個(gè)叫CircularReveal的家伙争便,可以做一下點(diǎn)擊按鈕之后跳轉(zhuǎn)activity的動(dòng)畫《弦剑回頭弄完再擼篇文章滞乙,等我~0
內(nèi)推信息
- 我們正在招募小伙伴奏纪,有興趣的小伙伴可以把簡歷發(fā)到 app@talkmoney.cn,備注:來自簡書社區(qū)
- 詳情可以戳這里--> 廣州蘆葦信息科技