版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、本文实例为家了 android 自定义带箭头对话框的具体代码,供家参考,具体内容如下import android.content.context; import android.content.res.typedarray; import android.graphics.canvas; import android.graphics.paint; import android.graphics.path; import android.support.annotation.nullable; import android.util.attributeset; import android.v
2、iew.gravity; import .sankuai.shangou.stone.util.densityutil; import .sankuai.waimai.store.search.r; /* * created by android studio. user: liangyongyao date: 2021/3/7 des: 带倒三角的气泡 */ public class bubblearrowtextview extends android.support.v7.widget.appcompattextview private final static int triangle
3、_direction_top = 1; private final static int triangle_direction_bottom = 2; private final static int triangle_direction_left = 1; private final static int triangle_direction_right = 2; private paint mpaint; private paint mstrokepaint; private int mbgcolor; private int mstrokecolor; private int mstro
4、kewidth; private int mtotalheight; private int mtotalwidth; private int mlabelheight; private int mtriangleheight; private int mtrianglewidth; private int mradius; private int triangledirection; public bubblearrowtextview(context context) this(context, null); public bubblearrowtextview(context conte
5、xt, nullable attributeset attrs) this(context, attrs, 0); public bubblearrowtextview(context context, nullable attributeset attrs, int defstyleattr) super(context, attrs, defstyleattr); init(context, attrs, defstyleattr); public void init(context context, attributeset attrs, int defstyleattr) if (at
6、trs != null) typedarray a = context.obtainstyledattributes(attrs, r.styleable.bubblearrowtextview); mbgcolor = a.getcolor(r.styleable.bubblearrowtextview_bubblecolor, 0); mstrokecolor = a.getcolor(r.styleable.bubblearrowtextview_bubblestrokecolor, 0); mradius = a.getdimensionpixeloffset(r.styleable.
7、bubblearrowtextview_bubbleradius, 0); mstrokewidth = a.getdimensionpixeloffset(r.styleable.bubblearrowtextview_bubblestrokewidth, 0); mtriangleheight = a.getdimensionpixeloffset(r.styleable.bubblearrowtextview_triangleheight, densityutil.dip2px(context, 6); mtrianglewidth = a.getdimensionpixeloffset
8、(r.styleable.bubblearrowtextview_trianglewidth, densityutil.dip2px(context, 3.5f); triangledirection = a.getint(r.styleable.bubblearrowtextview_triangledirection, 0); a.recycle(); setgravity(gravity.center); initpaint(); / 初始化画笔 public void initpaint() mpaint = new paint(); mpaint.setantialias(true)
9、; mpaint.setstyle(paint.style.fill); mpaint.settextsize(getpaint().gettextsize(); mpaint.setdither(true); / 初始化边框线画笔 public void initstrokepaint() mstrokepaint = new paint(); mstrokepaint.setantialias(true); mstrokepaint.setstyle(paint.style.fill); mstrokepaint.setdither(true); override protected vo
10、id onmeasure(int widthmeasurespec, int heightmeasurespec) super.onmeasure(widthmeasurespec, heightmeasurespec); mlabelheight = getfontheight() + getpaingtop() + getpaingbottom(); mtotalheight = mlabelheight + mtriangleheight * 2 + mstrokewidth * 2; mtotalwidth = getpaingleft() + getfontwidth() + get
11、paingright() + mstrokewidth * 2; setmeasureddimension(mtotalwidth, mtotalheight); override protected void ondraw(canvas canvas) drawview(canvas); super.ondraw(canvas); / 绘制气泡 private void drawview(canvas canvas) if (mstrokecolor != 0 & mstrokewidth != 0) initstrokepaint(); mstrokepaint.setcolor(
12、mstrokecolor); drawround(canvas, mstrokepaint, 0); drawtriangle(canvas, mstrokepaint, 0); if (mbgcolor != 0) mpaint.setcolor(mbgcolor); drawround(canvas, mpaint, mstrokewidth); drawtriangle(canvas, mpaint, mstrokewidth); / 绘制矩形 private void drawround(canvas canvas, paint paint, int strokewidth) canv
13、as.drawroundrect(strokewidth, mtriangleheight + strokewidth, mtotalwidth - strokewidth, mtotalheight - mtriangleheight - strokewidth, mradius, mradius, paint); / 绘制三角形 private void drawtriangle(canvas canvas, paint paint, int strokewidth) path path = new path(); switch (triangledirection) / 上 case t
14、riangle_direction_top: path.moveto(mtotalwidth * 0.8f - mtrianglewidth / 2 + strokewidth / 2, mtriangleheight + strokewidth); path.lineto(mtotalwidth * 0.8f, strokewidth + strokewidth / 2); path.lineto(mtotalwidth * 0.8f + mtrianglewidth / 2 - strokewidth / 2, mtriangleheight + strokewidth); break;
15、/ 下 case triangle_direction_bottom: path.moveto(mtotalwidth * 0.8f - mtrianglewidth/2 + strokewidth / 2, mtotalheight - mtriangleheight - strokewidth); path.lineto(mtotalwidth * 0.8f, mtotalheight - strokewidth - strokewidth / 2); path.lineto(mtotalwidth * 0.8f + mtrianglewidth/2 - strokewidth / 2, mtotalheight - mtriangleheight - strokewidth); break; default: return; canvas.drawpath(path, paint); / 根据字号求字体高度 private int getfontheight() pai
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 随州职业技术学院《化工原理实验一》2024-2025学年第二学期期末试卷
- 智能网联汽车技术与应用 课件 第3章 智能网联汽车环境感知
- 道路客运服务员道德考核试卷含答案
- 服装定型工安全理论水平考核试卷含答案
- 啤酒花加工工安全实践水平考核试卷含答案
- 继电器线圈绕制工操作管理强化考核试卷含答案
- 电线电缆挤塑工操作技能模拟考核试卷含答案
- 柔性版制版员岗前强化考核试卷含答案
- 通信交换设备装调工岗前成果考核试卷含答案
- 固体化妆品制造工安全技能强化考核试卷含答案
- 二手房买卖合同样本下载链接
- 《春天来了》(课件)-【知识精研】花城版音乐三年级下册
- 2024年12月2025中国道教协会公开招聘应届高校毕业生5人笔试历年典型考题(历年真题考点)解题思路附带答案详解
- 根及根茎类中药的鉴定(中药鉴定学课件)
- 《工程勘察设计收费标准》(2002年修订本)-完整版-1
- 有关酒的论文开题报告
- DB11-T 213-2022 城镇绿地养护技术规范
- 《机器人竞赛与实训》教学大纲
- QB/T 6019-2023 制浆造纸专业设备安装工程施工质量验收规范 (正式版)
- 人教版九年级单词默写汉译英打印版
- 2024年山东烟台高三一模语文试题答案详解讲评课件
评论
0/150
提交评论