版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 金属冶炼行业铅冶炼液态高铅渣直接还原技术研发项目技术创新总结报告
- 综合体项目地铁盾构隧道施工方案
- 地源热泵验收标准
- 2026年家政服务公司养老护理部经理工作计划
- 医务人员锐器伤的处理方法及流程培训试题及答案
- 易制毒化学品经营企业操作员检修维修安全操作规程
- 焊接企业应急救援预案
- 配送企业安全检查制度
- 证券公司突发事故应急预案演练脚本
- 职业病防护单位班组安全活动制度
- 2026年全国中级经济师之中级经济师经济基础知识考试综合能力题详细参考解析
- 等离子体灭菌工程化设计-全面剖析
- 内蒙古自治区赤峰市松山区2024-2025学年八年级上学期期末物理试题(原卷版+解析版)
- 实习协议合同模板范本
- 省植保无人飞机操作技能竞赛备赛试题及答案
- 河北省张家口市2024-2025学年高一物理下学期期末考试试题
- 某大型工程项目部临建施工方案(技术方案)
- CJT 288-2017 预制双层不锈钢烟道及烟囱
- 2024年成都西岭文旅投资运营集团有限公司招聘笔试冲刺题(带答案解析)
- GD T 形状及位置公差分析(一)
- 女性不孕症研究白皮书
评论
0/150
提交评论