国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android懸浮按鈕的使用方法

2019-12-12 00:49:29
字體:
來源:轉載
供稿:網友

懸浮按鈕效果如下圖所示:

步驟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" // 按鈕打開后,主按鈕和子按鈕的距離
  • imageSize="50dp" // 按鈕大小,所占區域的邊長
  • marginY="100dp" // 與上下邊緣距離,下圖中黃色部分的高度
  • number="6" // 展開的子按鈕的數量,可以是3-6個
  • imageMainOpen="@mipmap/suspendMainOpen" // 中間按鈕展開時的圖片資源
  • imageMainClose="@mipmap/suspendMainClose" // 中間按鈕關閉時的圖片資源
  • image1="@mipmap/suspend_1" // 子按鈕的圖片資源,image1~image6

步驟3:Activity使用

public class MainActivity extends AppCompatActivity {   public String[] suspendChildButtonInfo = {"相機", "音樂", "地圖", "亮度", "聯系人", "短信"};   @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, "您點擊了【"       + suspendChildButtonInfo[index - 1] + "】按鈕!", Toast.LENGTH_SHORT).show();    }   });  /**   * suspendButtonLayout.hideSuspendButton(); // 隱藏按鈕   suspendButtonLayout.showSuspendButton(); // 顯示按鈕    suspendButtonLayout.openSuspendButton(); // 展開按鈕   suspendButtonLayout.closeSuspendButton(); // 關閉按鈕    suspendButtonLayout.setMainCloseImageResource(R.mipmap.suspend_main_close); // 設置關閉時,主按鈕的圖片   suspendButtonLayout.setMainOpenImageResource(R.mipmap.suspend_main_open); // 設置展開時,主按鈕的圖片    // 設置按鈕位置。isRight:true在右邊,false在左邊;stayPosY:在'按鈕停留區域'從上往下,值為從0到100。   suspendButtonLayout.setPosition(isRight, stayPosY); */    } } 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 谷城县| 昌黎县| 孝义市| 礼泉县| 蒙阴县| 文成县| 乌恰县| 长海县| 左云县| 旬阳县| 临沭县| 建平县| 樟树市| 顺昌县| 图们市| 辉县市| 潜山县| 山阴县| 玉屏| 江北区| 新邵县| 广西| 长沙市| 盘山县| 杭州市| 拉萨市| 沁水县| 湖口县| 吉木萨尔县| 黄陵县| 睢宁县| 洞头县| 滦平县| 长治市| 阳东县| 龙井市| 邵东县| 铜川市| 都安| 长子县| 兴城市|