Android悬浮按钮的使用方法

所属分类: 软件编程 / Android 阅读数: 45
收藏 0 赞 0 分享

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

步骤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); */ 
 
 
 } 
} 

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

更多精彩内容其他人还在看

使用ViewPager实现android软件使用向导功能实现步骤

现在的大部分android软件,都是使用说明,就是第一次使用该软件时,会出现向导,可以左右滑动,然后就进入应用的主界面了,下面我们就实现这个功能
收藏 0 赞 0 分享

android在异步任务中关闭Cursor的代码方法

android在异步任务中如何关闭Cursor?在我们开发应用的时候,很多时候会遇到这种问题,下面我们就看看代码如何实现
收藏 0 赞 0 分享

Android自定义桌面功能代码实现

android自定义桌面其实很简单,看一个例子就明白了
收藏 0 赞 0 分享

android将图片转换存到数据库再从数据库读取转换成图片实现代码

有时候我们想把图片存入到数据库中,尽管这不是一种明智的选择,但有时候还是不得以会用到,下面说说将图片转换成byte[]数组存入到数据库中去,并从数据库中取出来转换成图像显示出来
收藏 0 赞 0 分享

TextView显示系统时间(时钟功能带秒针变化

用System.currentTimeMillis()可以获取系统当前的时间,我们可以开启一个线程,然后通过handler发消息,来实时的更新TextView上显示的系统时间,可以做一个时钟的功能
收藏 0 赞 0 分享

Android用ListView显示SDCard文件列表的小例子

本文简单实现了用ListView显示SDCard文件列表,目录的回退等功能暂不讨论,获取文件列表,files即为所选择目录下的所有文件列表
收藏 0 赞 0 分享

Android拦截外拨电话程序示例

这篇文章主要介绍了Android拦截外拨电话的示例,大家参考使用吧
收藏 0 赞 0 分享

通过Html网页调用本地安卓(android)app程序代码

如何使用html网页和本地app进行传递数据呢?经过研究,发现还是有方法的,总结了一下,大致有一下几种方式
收藏 0 赞 0 分享

android Textview文字监控(Textview使用方法)

以手机号充值为例,当用户输入最后一位数时候,进行汇率的变换,本文就实现类似这样的功能
收藏 0 赞 0 分享

Android ListView长按弹出菜单二种实现方式示例

这篇文章主要介绍了Android ListView长按弹出菜单的方法,大家参考实现
收藏 0 赞 0 分享
查看更多