前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android悬浮按钮的使用方法

Android悬浮按钮的使用方法

作者头像
砸漏
发布2020-11-05 09:59:10
1.7K0
发布2020-11-05 09:59:10
举报
文章被收录于专栏:恩蓝脚本

悬浮按钮效果如下图所示:

步骤1:引用

代码语言:javascript
复制
compile 'com.laocaixw.suspendbuttonlayout:suspendbuttonlayout:1.0.3' 

步骤2:xml布局

代码语言:javascript
复制
<?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使用

代码语言:javascript
复制
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); */ 
 
 
 } 
} 

以上就是本文的全部内容,希望对大家的学习有所帮助。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
短信
腾讯云短信(Short Message Service,SMS)可为广大企业级用户提供稳定可靠,安全合规的短信触达服务。用户可快速接入,调用 API / SDK 或者通过控制台即可发送,支持发送验证码、通知类短信和营销短信。国内验证短信秒级触达,99%到达率;国际/港澳台短信覆盖全球200+国家/地区,全球多服务站点,稳定可靠。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档