
VIEwOutlineProvIDer provIDer = new VIEwOutlineProvIDer() { @OverrIDe public voID getoutline(VIEw vIEw,Outline outline) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LolliPOP) { configurePath(getWIDth(),getHeight()); outline.setConvexPath(borderPath); } } }; setoutlineProvIDer(provIDer); setClipToOutline(true); configurePath()看起来像这样:
private voID configurePath (int wIDth,int height) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LolliPOP) { return; } borderPath.rewind(); float minSize = Math.min(wIDth,height); float maxRadiusWIDth = 2 * Math.max(Math.max(topLefTradius,topRighTradius),Math.max(bottomLefTradius,bottomrighTradius)); if (minSize < maxRadiusWIDth) { borderPath.addRect(0,wIDth,height,Path.Direction.ccw); return; } // top left circle oval.set(0,2 * topLefTradius,2 * topLefTradius); borderPath.moveto(0,topLefTradius); borderPath.arcTo(oval,180,-90); borderPath.rlineto(wIDth - topLefTradius - topRighTradius,0); // top right circle oval.set(wIDth - 2 * topRighTradius,2 * topRighTradius); borderPath.arcTo(oval,90,-90); borderPath.rlineto(0,height - topRighTradius - bottomrighTradius); // Bottom right circle oval.set(wIDth - 2 * bottomrighTradius,height - 2 * bottomrighTradius,height); borderPath.arcTo(oval,-90); borderPath.rlineto(-wIDth + bottomrighTradius + bottomLefTradius,0); // Bottom left circle oval.set(0,height - 2 * bottomLefTradius,2 * bottomLefTradius,-90,-height + bottomLefTradius + topLefTradius);} 当我运行它时,我得到java.lang.IllegalArgumentException:path必须是凸的,我无法进入native_isConvex()并看看它是如何决定路径是否凸出.
那么什么是凸路?为什么congfigurePath()中的路径不是凸的?
如何创建自定义凸路径?谢谢.
// top left circle oval.set(0,-180,90); borderPath.rlineto(wIDth - topLefTradius - topRighTradius,90); borderPath.rlineto(0,90); borderPath.rlineto(-wIDth + bottomrighTradius + bottomLefTradius,-height + bottomLefTradius + topLefTradius);
更新:虽然现在路径正确,但它仍然不是凸路径,似乎自定义路径不会被视为凸路径.
总结以上是内存溢出为你收集整理的创建自定义凸路径Android全部内容,希望文章能够帮你解决创建自定义凸路径Android所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)