java - 在android中以编程方式绘制圆形
解决方案
要以编程方式实现圆形可绘制,您需要具有如下功能。
public static GradientDrawable drawCircle(int backgroundColor, int borderColor) {
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.OVAL);
shape.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0});
shape.setColor(backgroundColor);
shape.setStroke(10, borderColor);
return shape;
}
并像下面这样设置drawable
你ImageView
的。
imageView.setBackground(drawCircle(getResources().getColor(android.R.color.holo_blue_dark), getResources().getColor(android.R.color.holo_red_dark)));
这是给这样的东西。
推荐阅读
- python - 在 for 循环中创建新的 Sequential 模型(使用 Keras)
- rest - 如何在 PowerShell 中使用 REST 发送数据
- php - 数组类型之间的区别 - PHP
- javascript - 基于移动视图宽度的移动元素不会恢复到原始桌面视图
- r - 如何在不同级别而不是 id 或时间对 plm 的标准错误进行聚类?
- python - Django post_delete:计算所有具有一个与已删除对象匹配的属性的对象
- aws-sdk-ruby - 将 AWS S3 Select 与适用于 Ruby 的 AWS 开发工具包一起使用时出现编码错误
- pdo - fetchAll() - 真的有必要吗?
- azure - Azure 数据工厂从 foreach 值中获取数据
- kubernetes - 自动将 imagePullSecrets 添加到 ServiceAccount