Android--垃圾桶控件
运用Path和Canvas旋转实现的效果
/*** 垃圾桶*/
public class BinView extends View {private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);private Bitmap bottomBitmap;//下面的高度private int bottomHeight = 50;//盖子宽度private int gaiziWidth = 100;//盖子初始Y坐标private int gaiziOffset;private Path gaiziPath;//旋转角度private float rotate = 1;public BinView(Context context) {super(context);}public BinView(Context context, @Nullable AttributeSet attrs) {super(context, attrs);mPaint.setStyle(Paint.Style.STROKE);mPaint.setColor(Color.BLACK);mPaint.setStrokeWidth(5);mPaint.setStrokeCap(Paint.Cap.ROUND);}@Overrideprotected void onDraw(Canvas canvas) {int centerX = canvas.getWidth() / 2;int centerY = canvas.getHeight() / 2;if (bottomBitmap == null) {//缓冲bottomBitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888);Canvas bottomCanvas = new Canvas(bottomBitmap);//画中间三条竖线int spac = 10;//每条线的间距Path path1 = new Path();path1.moveTo(centerX, centerY);path1.lineTo(centerX, centerY + bottomHeight);Path path2 = new Path();path2.moveTo(centerX - spac, centerY);path2.lineTo(centerX - spac, centerY + bottomHeight);Path path3 = new Path();path3.moveTo(centerX + spac, centerY);path3.lineTo(centerX + spac, centerY + bottomHeight);bottomCanvas.drawPath(path1, mPaint);bottomCanvas.drawPath(path2, mPaint);bottomCanvas.drawPath(path3, mPaint);//底部int bottomWidth = 40;Path path4 = new Path();path4.moveTo(centerX - bottomWidth / 2, centerY + spac + bottomHeight);path4.lineTo(centerX + bottomWidth / 2, centerY + spac + bottomHeight);bottomCanvas.drawPath(path4, mPaint);//画左边斜线bottomCanvas.save();bottomCanvas.rotate(-15, centerX - bottomWidth / 2, centerY + spac + bottomHeight);Path path5 = new Path();path5.moveTo(centerX - bottomWidth / 2, centerY + spac + bottomHeight);path5.lineTo(centerX - bottomWidth / 2, centerY - spac);bottomCanvas.drawPath(path5, mPaint);bottomCanvas.restore();//画右边斜线bottomCanvas.save();bottomCanvas.rotate(15, centerX + bottomWidth / 2, centerY + spac + bottomHeight);Path path6 = new Path();path6.moveTo(centerX + bottomWidth / 2, centerY + spac + bottomHeight);path6.lineTo(centerX + bottomWidth / 2, centerY - spac);bottomCanvas.drawPath(path6, mPaint);bottomCanvas.restore();gaiziOffset = spac;}//画底部缓冲canvas.drawBitmap(bottomBitmap, 0, 0, mPaint);//画盖子if (gaiziPath == null) {gaiziPath = new Path();gaiziPath.moveTo(centerX - gaiziWidth / 2, centerY - gaiziOffset);gaiziPath.lineTo(centerX + gaiziWidth / 2, centerY - gaiziOffset);int gaiziHeadWidth = 10;gaiziPath.addRect(centerX - gaiziHeadWidth, centerY - gaiziHeadWidth - gaiziOffset, centerX + gaiziHeadWidth, centerY - gaiziOffset, Path.Direction.CW);}canvas.save();canvas.rotate(45 * (1 - rotate), centerX + gaiziWidth / 2, centerY - gaiziOffset);canvas.drawPath(gaiziPath, mPaint);canvas.restore();}@Overridepublic boolean onTouchEvent(MotionEvent event) {if (event.getAction() == MotionEvent.ACTION_DOWN) {startAnime();}return super.onTouchEvent(event);}private ValueAnimator valueAnimator;public void startAnime() {if (valueAnimator == null) {valueAnimator = ValueAnimator.ofFloat(1);valueAnimator.setInterpolator(new LinearInterpolator());valueAnimator.setDuration(1000);valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {@Overridepublic void onAnimationUpdate(ValueAnimator animation) {rotate = (float) animation.getAnimatedValue();postInvalidate();}});}valueAnimator.start();}
}
项目地址:https://gitee.com/aruba/CanvasApplication.git
http://www.taodudu.cc/news/show-5606931.html
相关文章:
- 单片机设计_语音识别分类智能垃圾桶(STM32 ESP8266 LD3320)
- C#.NetWPF实现垃圾桶案例
- 基于WemosD1的智能垃圾桶
- 垃圾桶溢出识别系统 opencv
- 仿网易‘垃圾箱’动画效果
- 炫酷安卓垃圾回收动画
- 基于Arduino的感应垃圾桶
- Andorid实现垃圾桶开关动画
- 垃圾桶
- android 清理内存图标掉进垃圾桶的动画,Android Magnet:桌面删除APP自动弹出垃圾桶接受图标删除动作...
- 自动感应垃圾桶c语言,如何使用STM32开发板作一个自动感应垃圾桶
- android 清理内存图标掉进垃圾桶的动画,垃圾桶 icon 小动效
- 写一个把控件丢到垃圾桶的动画其实很简单
- 【转载】android开发新浪微博客户端 完整攻略
- android开发新浪微博客户端 完整攻略 [新手必读]
- android开发新浪微博客户端
- 浅谈微博
- android 新浪微博客户端开发
- InFrame Cut: 微博拼图的时候用用这个
- 腾讯微博项目
- 分享如何搭建个人网站/微博
- CentOS 7.9 离线软件包下载
- microsoft windows 系统更新包下载与离线安装
- Linux离线更新conda
- linux clamav 离线更新病毒库
- 离线更新glibc
- python中插件离线下载
- 离线 安装更新pip,以及pip离线下载 whl包
- kali安装Nessus与离线更新
- Windows Server 2016离线安装更新包
Android--垃圾桶控件相关推荐
- Android开源控件ViewPager Indicator的使用方法
1月16日厦门 OSC 源创会火热报名中,奖品多多哦 摘要 Android开源控件ViewPager Indicator的使用介绍 ViewPagerIndicator 目录[-] 1. V ...
- 日历控件的android代码,Android日历控件PickTime代码实例
Android日历控件PickTime代码实例 发布时间:2020-10-03 16:05:51 来源:脚本之家 阅读:86 作者:手撕高达的村长 最近做项目,需要设置用户的生日,所以做这样一个功能. ...
- android 获取控件高度_安卓开发入门教程UI控件_ImageView
什么是ImageView ImageView是用于显示图片的UI控件. 基础样例 1.展示本地图片 效果图 代码 <ImageViewandroid:layout_width="wra ...
- xamarin.android 控件,Android 库控件 - Xamarin | Microsoft Docs
Xamarin Android 库控件Xamarin.Android Gallery control 03/15/2018 本文内容 Gallery是一种布局小组件,用于显示水平滚动列表中的项,并将当 ...
- android 获取控件在屏幕中的坐标
今天,简单讲讲android如何获取控件在屏幕中的坐标. 这个其实也很简单,但是昨天做一个功能时,需要功能控件的坐标做一些逻辑操作时,居然不知道怎么做.所以在网上查找了资料后,解决了这个问题.这里记录 ...
- Android图表控件MPAndroidChart——曲线图LineChart的使用(财富收益图)
目录 前言 本文涉及文章 其他相关文章 1.数据准备 1.1 数据来源 2.曲线展示 2.1 MPAndroidChart获取 2.2 数据对象获取 2.3 数据展示 3.曲线完善 3.1 图表背景. ...
- Android AutoCompleteTextView控件实现类似百度搜索提示,限制输入数字长度
Android AutoCompleteTextView 控件实现类似被搜索提示,效果如下 1.首先贴出布局代码 activity_main.xml: <?xml version="1 ...
- android控件使用大全,Android常见控件使用详解
本文实例为大家分享了六种Android常见控件的使用方法,供大家参考,具体内容如下 1.TextView 主要用于界面上显示一段文本信息 2.Button 用于和用户交互的一个按钮控件 //为Butt ...
- android组件用法说明,Android第三方控件PhotoView使用方法详解
Android第三方控件PhotoView使用方法详解 发布时间:2020-10-21 15:06:09 来源:脚本之家 阅读:74 作者:zhaihaohao1 PhotoView的简介: 这是一个 ...
- 系出名门Android(7) - 控件(View)之ZoomControls, Include, VideoView, WebView, RatingBar, Tab
[索引页] [×××] 系出名门Android(7) - 控件(View)之ZoomControls, Include, VideoView, WebView, RatingBar, Tab, Spi ...
最新文章
- hibernate中持久化对象的生命周期(三态:自由态,持久态,游离态 之间的转换)...
- 表驱动设计的一点见解
- 微信小程序,图片居中显示,适配不同机型
- mybatis-一对一的关联查询有两种配置方式
- Fortran执行语句中的“双冒号” ::
- 【转】Dynamics 365中开发和注册插件介绍
- flash builder eclipse插件安装
- 查看编译class文件时,使用的JDK版本(只能查看到大版本)
- 变量的语法扩展(JS)
- 在LaTeX中使用Python highlighting in LaTeX让python代码高亮
- 【Allennlp】: 怎样创建Allennlp中的Configuration文件
- php 类库 添加,如何在thinkphp5中添加自己的类库
- 怎么把程序下载到stc15w201s_STC15W201S系列
- unity 录屏插件总结 以及 AVProMovieCapture 5.0.0 安卓录制失败问题
- notimplementedexception
- 【javaScript】原生实现窗口拖动效果
- UDS诊断服务—物理寻址,功能寻址区别
- widget窗口小部件
- 视频中的自监督学习:Removing the background忽略视频的背景,学习robust的特征
- kinect fusion 3D扫描
热门文章
- Excel多级下拉菜单制作
- php随机分配班级座位,老师们是如何安排班级座位的?原来有一套准则!
- 解决w ndows7basic,win7出现提示“配色方案已更改为Windows7 Basic”该怎么解决
- 我那个卧了槽的程序猿男友
- With用法-Python
- 【转】Save SHSH Blobs for iPhone, iPad, iPod Touch with TinyUmbrella
- 微软Bing版ChatGPT表明想做人类,并且对纽约时报专栏作家表达爱意
- win7控制面板打不开的解决办法
- 关于影像exif信息保存的问题
- css 文字溢出隐藏 css 文字溢出隐藏无效解决办法