android自定义带箭头对话框_第1页
android自定义带箭头对话框_第2页
android自定义带箭头对话框_第3页
android自定义带箭头对话框_第4页
android自定义带箭头对话框_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论