问题描述
在使用自定义视图的画布中绘制自定义路径后,我使用pathClass创建了自定义圆角正方形形状。当我向视图添加更多高度时,比如说300高度和100宽度,但是当宽度更大时,它会移到顶部而不是视图的中心,自定义形状会向左移。出现在x,y中。这是路径代码:
public static Path roundRectSquare(int height,int width,float topLefTradius,float topRighTradius,float bottomrighTradius,float bottomLefTradius){
Path path = new Path();
RectF bl = new RectF(0,height -2* bottomLefTradius,2* bottomLefTradius,height);
RectF br = new RectF(width -2* bottomrighTradius,height -2* bottomrighTradius,width,height);
RectF tl = new RectF(0,2* topLefTradius,2* topLefTradius);
RectF tr = new RectF(width -2* topRighTradius,2* topRighTradius);
path.reset();
path.moveto(x + topLefTradius,y);
path.lineto(width - topRighTradius,y);
path.arcTo(tr,-90,90);
path.lineto(width,y + topRighTradius);
path.lineto(width,height - bottomrighTradius);
path.arcTo(br,90);
path.lineto(width - bottomrighTradius,height);
path.lineto(x + bottomLefTradius,height);
path.arcTo (bl,90,90);
path.lineto(x,height - bottomLefTradius);
path.lineto(x,y + topLefTradius);
path.arcTo(tl,180);
path.close();
return path;
}
in the path code x and y are getWidth/2 and getHeight/2
@Override
public void draw(Canvas canvas) {
path = new Path();
BoxPaint =new Paint();
int side = Math.min(this.getHeight(),this.getWidth());
BoxPaint.setStyle(Paint.Style.FILL);
BoxPaint.setColor(Color.YELLOW);
path = roundRectSquare(side,side,30,20,50,10);
canvas.drawPath(path,BoxPaint);
super.draw(canvas);
}
那么有什么办法可以解决这个问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)