java - 带圆角的六边形 ImageView
问题描述
我正在尝试制作一个带有圆角的六边形图像视图,这得益于我找到的一些代码并使用弧线来绘制角。这种方法不起作用可能是因为我做错了什么。我也希望有更简单的方法。
这是我的第一个圆角的代码,但结果并不好。
private void calculatePath(float radius) {
float halfRadius = radius / 2f;
float triangleHeight = (float) (Math.sqrt(3.0) * halfRadius);
float centerX = getMeasuredWidth() / 2f;
float centerY = getMeasuredHeight() / 2f;
this.hexagonPath.reset();
this.hexagonPath.moveTo(centerX, centerY + radius);
this.hexagonPath.lineTo(centerX - triangleHeight / 4f * 3f, centerY + radius / 8f * 5f);
this.hexagonPath.arcTo(new RectF(centerX - triangleHeight, centerY + radius / 8f * 5f, centerX - triangleHeight / 4f * 3f, centerY + halfRadius / 2f), 30f, 180f);
this.hexagonPath.lineTo(centerX - triangleHeight, centerY - halfRadius);
this.hexagonPath.lineTo(centerX, centerY - radius);
this.hexagonPath.lineTo(centerX + triangleHeight, centerY - halfRadius);
this.hexagonPath.lineTo(centerX + triangleHeight, centerY + halfRadius);
this.hexagonPath.close();
invalidate();
}
如您所见,这是没有任何弧的结果:
请帮助我找到解决方案或更简单的方法。
另外请不要链接我的库,我想自己为我的应用程序执行此操作。
对不起我的英语,不是我的主要语言。
解决方案
推荐阅读
- azure - 是否可以将不变性策略应用于 Azure Blob 块?
- elasticsearch - 在一处查看多个 kibana 仪表板
- sql-server - 防止相同的行插入到表中
- android - How do you make a Horizontal Number Picker Widget in Flutter?
- ecmascript-6 - 如何解决“找不到模块'gulp-babel'”?
- outlook - 如何在 office.js 中获取邮件的接收日期?
- android - 不同设备上的奇怪按钮
- android - 为什么更新应用程序时清除内部文件夹(context.filesDir)?
- pandas - Groupby 过滤器,基于连续序列排序和 ID 和日期列
- javascript - 在离线(无网络)模式下显示 SVG