Android懸浮按鈕的使用方法
懸浮按鈕效果如下圖所示:
步驟1:引用
compile 'com.laocaixw.suspendbuttonlayout:suspendbuttonlayout:1.0.3'
步驟2:xml布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:suspend="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"> <com.laocaixw.layout.SuspendButtonLayout android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="match_parent" suspend:distance="80dp" suspend:imageSize="50dp" suspend:marginY="100dp" suspend:number="6" suspend:imageMainOpen="@mipmap/suspend_main_open" suspend:imageMainClose="@mipmap/suspend_main_close" suspend:image1="@mipmap/suspend_1" suspend:image2="@mipmap/suspend_2" suspend:image3="@mipmap/suspend_3" suspend:image4="@mipmap/suspend_4" suspend:image5="@mipmap/suspend_5" suspend:image6="@mipmap/suspend_6"> </com.laocaixw.layout.SuspendButtonLayout> </LinearLayout>
以上各屬性:
- distance="80dp" // 按鈕打開(kāi)后,主按鈕和子按鈕的距離
- imageSize="50dp" // 按鈕大小,所占區(qū)域的邊長(zhǎng)
- marginY="100dp" // 與上下邊緣距離,下圖中黃色部分的高度
- number="6" // 展開(kāi)的子按鈕的數(shù)量,可以是3-6個(gè)
- imageMainOpen="@mipmap/suspendMainOpen" // 中間按鈕展開(kāi)時(shí)的圖片資源
- imageMainClose="@mipmap/suspendMainClose" // 中間按鈕關(guān)閉時(shí)的圖片資源
- image1="@mipmap/suspend_1" // 子按鈕的圖片資源,image1~image6
步驟3:Activity使用
public class MainActivity extends AppCompatActivity { public String[] suspendChildButtonInfo = {"相機(jī)", "音樂(lè)", "地圖", "亮度", "聯(lián)系人", "短信"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_suspendbutton); final SuspendButtonLayout suspendButtonLayout = (SuspendButtonLayout) findViewById(R.id.layout); suspendButtonLayout.setOnSuspendListener(new SuspendButtonLayout.OnSuspendListener() { @Override public void onButtonStatusChanged(int status) { } @Override public void onChildButtonClick(int index) { Toast.makeText(MainActivity.this, "您點(diǎn)擊了【" + suspendChildButtonInfo[index - 1] + "】按鈕!", Toast.LENGTH_SHORT).show(); } }); /** * suspendButtonLayout.hideSuspendButton(); // 隱藏按鈕 suspendButtonLayout.showSuspendButton(); // 顯示按鈕 suspendButtonLayout.openSuspendButton(); // 展開(kāi)按鈕 suspendButtonLayout.closeSuspendButton(); // 關(guān)閉按鈕 suspendButtonLayout.setMainCloseImageResource(R.mipmap.suspend_main_close); // 設(shè)置關(guān)閉時(shí),主按鈕的圖片 suspendButtonLayout.setMainOpenImageResource(R.mipmap.suspend_main_open); // 設(shè)置展開(kāi)時(shí),主按鈕的圖片 // 設(shè)置按鈕位置。isRight:true在右邊,false在左邊;stayPosY:在'按鈕停留區(qū)域'從上往下,值為從0到100。 suspendButtonLayout.setPosition(isRight, stayPosY); */ } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android App中制作仿MIUI的Tab切換效果的實(shí)例分享
這篇文章主要介紹了Android App中制作仿MIUI的Tab切換效果的實(shí)例分享,實(shí)現(xiàn)具有跟隨手指滾動(dòng)而滾動(dòng)功能的ViewPagerIndicator,需要的朋友可以參考下2016-04-04android利用消息機(jī)制獲取網(wǎng)絡(luò)圖片
這篇文章主要為大家詳細(xì)介紹了android利用消息機(jī)制獲取網(wǎng)絡(luò)圖片的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03Android界面設(shè)計(jì)(APP設(shè)計(jì)趨勢(shì) 左側(cè)隱藏菜單右邊顯示content)
這文章講述了2013年未來(lái)的移動(dòng)APP設(shè)計(jì)趨勢(shì),感覺(jué)挺有道理的:Android界面設(shè)計(jì)實(shí)現(xiàn)左側(cè)隱藏菜單右邊顯示content,感興趣的你可以了解下啊,希望本文對(duì)你的APP設(shè)計(jì)提高有所幫助哦2013-01-01Android提高之藍(lán)牙傳感應(yīng)用實(shí)例
這篇文章主要介紹了Android的藍(lán)牙傳感應(yīng)用實(shí)例,對(duì)于Android項(xiàng)目開(kāi)發(fā)來(lái)說(shuō)非常實(shí)用,需要的朋友可以參考下2014-08-08Android自定義View仿QQ等級(jí)天數(shù)進(jìn)度
這篇文章主要為大家詳細(xì)介紹了Android自定義View仿QQ等級(jí)天數(shù)進(jìn)度效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07Flutter?Animation實(shí)現(xiàn)縮放和滑動(dòng)動(dòng)畫(huà)效果
這篇文章主要為大家詳細(xì)介紹了Flutter?Animation實(shí)現(xiàn)縮放和滑動(dòng)動(dòng)畫(huà)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03Android 圓角邊框的實(shí)現(xiàn)方式匯總
這篇文章主要介紹了Android 圓角邊框的實(shí)現(xiàn)方式匯總的相關(guān)資料,需要的朋友可以參考下2016-03-03一文了解Android?ViewModelScope?如何自動(dòng)取消協(xié)程
這篇文章主要介紹了一文了解Android?ViewModelScope?如何自動(dòng)取消協(xié)程,文章圍繞主題站展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定參考價(jià)值,感興趣的小伙伴可以參考一下2022-07-07android開(kāi)發(fā)教程之判斷是手機(jī)還是平板的方法
判斷是平板還是手機(jī),通過(guò)很多的方式都可以實(shí)現(xiàn),如:設(shè)備尺寸、DPI、版本號(hào)、是否具備電話功能等,不過(guò)有些沒(méi)有那么的精準(zhǔn),這里分享一個(gè)比較簡(jiǎn)潔的方法2014-04-04