非常感谢.
附加代码:rect的红色角落.
过去的代码:
public class MPCTextVIEw extends TextVIEw { // private Context context; private final static String TAG = "MPCTextVIEw"; public final static int DEFAulT_BACKGROUND_color = color .parsecolor("#28FF28"); public final static int DEFAulT_border_color = color.parsecolor("#FF0000"); public int mBoderWIDth = 2; public int mBodercolor; public int mBoderRadius = 20; public int mbackgroundcolor; public boolean isHaveborder = true; public boolean isHaveBackground = true; RectF mRectF = new RectF(); Rect mRec = new Rect(); Paint mPaint = new Paint(); public MPCTextVIEw(Context context) { super(context); // this.context = context; } @OverrIDe protected voID onDraw(Canvas canvas) { // try to add a boder for this vIEw. canvas.getClipBounds(mRec); // draw background // canvas.drawcolor(mbackgroundcolor); mPaint.setStyle(Paint.Style.FILL); mPaint.setcolor(DEFAulT_BACKGROUND_color); if (mBoderRadius > 0) { mRectF.set(mRec); canvas.drawRoundRect(mRectF,mBoderRadius,mPaint); } else { canvas.drawRect(mRec,mPaint); } mPaint.setStyle(Paint.Style.stroke); mPaint.setstrokeWIDth(mBoderWIDth); mPaint.setcolor(DEFAulT_border_color); mPaint.setAntiAlias(true); if (mBoderRadius > 0) { mRectF.set(mRec); canvas.drawRoundRect(mRectF,mPaint); } super.onDraw(canvas); }解决方法 问题的核心是填充,而不是AntiAliasing.角落不厚,而是正常宽度.但是,直线被剪裁了.
如果将笔触宽度设置为2,则实际直线宽度为1,因为笔划为矩形,轴为x = 0.这意味着矩形为(left = 0,up = -1,right = length,bottom = 1),但是up -1在画布之外,因此它不会被绘制.角落是全宽的,因为它在画布上.
所以,你只需要设置填充.
下面是在画布中完全圆化rect绘制的代码:
float pad = 1f;mRectF.set(new RectF(mRec.left + pad,mRec.top + pad,mRec.right - pad,mRec.bottom - pad));canvas.drawRoundRect(mRectF,mPaint);总结
以上是内存溢出为你收集整理的android – 如何使边框更流畅全部内容,希望文章能够帮你解决android – 如何使边框更流畅所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)