Android自定义可拖拽的悬浮按钮DragFloatingActionButton
Android自定义可拖拽的悬浮按钮DragFloatingActionButton Android自定义可拖拽的悬浮按钮DragFloatingActionButton是Android 5.0系统添加的新控件,它继承至ImageView,因此拥有ImageView的所有属性。下面是对Android自定义可拖拽的悬浮按钮DragFloatingActionButton的详细介绍。 一、悬浮按钮FloatingActionButton的基本使用 悬浮按钮FloatingActionButton的基本使用非常简单,首先需要添加依赖 compile 'com.android.support:design:25.3.1',然后在布局文件中使用。例如: ```xml <android.support.design.widget.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|bottom" android:src="@drawable/ic_launcher" /> ``` 悬浮按钮FloatingActionButton正常显示的情况下有个填充的颜色,有个阴影;点击的时候会有一个rippleColor,并且阴影的范围可以增大。 二、悬浮按钮FloatingActionButton的属性 悬浮按钮FloatingActionButton有三个重要的属性: 1. 填充的颜色,默认使用的是style当中的colorAccent。 2. rippleColor,默认取的是Theme当中的colorControlHighlight。 3. elevation和pressedTranslationZ,前者用户设置正常显示的阴影大小;后者是点击时显示的阴影大小。 三、自定义可拖拽的悬浮按钮DragFloatActionButton 下面是自定义可拖拽的悬浮按钮DragFloatActionButton的代码: ```java import android.animation.ObjectAnimator; import android.content.Context; import android.support.design.widget.FloatingActionButton; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.view.animation.DecelerateInterpolator; public class DragFloatActionButton extends FloatingActionButton { private int screenWidth; private int screenHeight; private int screenWidthHalf; private int statusHeight; private int virtualHeight; public DragFloatActionButton(Context context) { super(context); init(); } public DragFloatActionButton(Context context, AttributeSet attrs) { super(context, attrs); init(); } public DragFloatActionButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { screenWidth = ScreenUtils.getScreenWidth(getContext()); screenWidthHalf = screenWidth / 2; screenHeight = ScreenUtils.getScreenHeight(getContext()); statusHeight = ScreenUtils.getStatusHeight(getContext()); virtualHeight = ScreenUtils.getVirtualBarHeigh(getContext()); } private int lastX; private int lastY; private boolean isDrag; @Override public boolean onTouchEvent(MotionEvent event) { // ... } } ``` 四、悬浮按钮FloatingActionButton的吸附功能 悬浮按钮FloatingActionButton的吸附功能可以通过在屏幕的边缘进行吸附,实现吸附边框的功能。 五、结论 Android自定义可拖拽的悬浮按钮DragFloatingActionButton是Android 5.0系统添加的新控件,它继承至ImageView,因此拥有ImageView的所有属性。通过自定义悬浮按钮FloatingActionButton,可以实现可拖拽的悬浮按钮,并添加类似于qq的吸附边框的功能。























- 粉丝: 3
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 新疆铁通数据库服务系统性能优化毕业设计开题报告.docx
- 人事管理信息化的改进对策及建议.docx
- 基因微阵列图像数据自动化提取的开题报告.docx
- 软件营销方案(3).docx
- 电子计算机与多媒体2知识课件.ppt
- 用C语言输出各种图形.doc
- cuhstsk手机项目管理流程框图.doc
- 2023年CAD技能竞赛之手机挂题目.doc
- 传输网络的幅频和相频特性ppt课件.ppt
- 计算机系统的物理安全公开课一等奖优质课大赛微课获奖课件.pptx
- 南开大学2021年9月《网络爬虫与信息提取》作业考核试题及答案参考9.docx
- 现代移动通信蔡跃明题参考答案.doc
- 基于单片机煤气浓度监控系统的设计-工控机.docx
- 基于计算机思维能力培养的计算机基础教学模式浅谈.docx
- 四川大学计算机组成原理知识点.doc
- 互联网时代下-医学发展的新方向.docx


