给浮窗布局画个关闭按纽
很多大佬做控件时都直接用图片,复制到项目时还要找图。。。现在直接画一个
直接上菜
<如图
xx,yy是位移,都为0就是左上角,右上角即xx=canvas的宽-圆的直径
float o圆的直径
int color颜色
void drawClose(Canvas canvas, float xx, float yy, float o,int color) {
float x=o/6,y=o-x,x1=xx+x,y1=xx+y,x2=x+yy,y2=y+yy;
Paint p =new Paint(),pa=new Paint();
pa.setColor(color);
pa.setStrokeWidth(4);
pa.setStyle(Paint.Style.STROKE);
canvas.drawOval(new RectF(xx, yy, xx+o,yy+o), pa);
p.setColor(color);
p.setStrokeWidth(4);
canvas.drawLine(y1, x2, x1, y2, p);
canvas.drawLine(x1, x2, y1, y2, p);
}
重写布局的直接在onDraw(Canvas canvas)里用
float o=60,xx=magnifierLen-80,yy=20;//修改变量
drawClose(canvas,xx,yy,o,Color.BLACK);
Bitmap的用法
Bitmap x()
{
float o=60;//修改变量
Bitmap b=Bitmap.createBitmap(o,o, Bitmap.Config.ARGB_8888);
Canvas v=new Canvas(b);
drawClose(v,0,0,o,Color.BLACK);
return b;
}
Drawable 的用法
Drawable x()
{
float o=60;//修改变量
Bitmap b=Bitmap.createBitmap(o,o, Bitmap.Config.ARGB_8888);
Canvas v=new Canvas(b);
drawClose(v,0,0,o,Color.BLACK);
Drawable d = new BitmapDrawable(b) ;
return d;
}
关闭按纽画风不和?那就改一下就行了
int ocolor//圆的颜色
int color//线的颜色
void drawClose(Canvas canvas, float xx, float yy, float o,int ocolor,int color) {
float x=o/6,y=o-x,x1=xx+x,y1=xx+y,x2=x+yy,y2=y+yy;
Paint p =new Paint(),pa=new Paint();
pa.setColor(ocolor);
canvas.drawOval(new RectF(xx, yy, xx+o,yy+o), pa);
p.setColor(color);
p.setStrokeWidth(4);
canvas.drawLine(y1, x2, x1, y2, p);
canvas.drawLine(x1, x2, y1, y2, p);
} 学习一下! 厉害 牛了 学习
页:
[1]