Android canvas画线-让线条变粗
这看起来应该有点微不足道,但是在我的 Android 应用程序中,我使用画布绘制一系列连接在一起的线条。由于某种原因,我的线条非常非常微弱。我想知道如何才能使线条变粗?这是我的代码..
for(int i=1; i<myArrayListOfValues.size(); i++){
Paint myPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
myPaint.setStrokeWidth(8/*1 /getResources().getDisplayMetrics().density*/);
myPaint.setColor(0xffff0000); //color.RED
canvas.drawLine(myArrayListOfValues.get(i), myArrayListOfValues.get(i), myArrayListOfValues.get(i-1), myArrayListOfValues.get(i-1), myPaint);
}
另一件事是..我绘制的线条和圆圈始终是黑色的.. setColor() 似乎从来没有任何效果。我尝试使用颜色名称(例如 color.red)甚至它们的十六进制值(例如 0xffff0000)
This seems like it should be somewhat trivial, however in my android app, I am using canvas to draw a series of lines that are connected together. For some reason my lines are very very faint and thin. I was wondering how can I make my lines thicker? Here is my code..
for(int i=1; i<myArrayListOfValues.size(); i++){
Paint myPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
myPaint.setStrokeWidth(8/*1 /getResources().getDisplayMetrics().density*/);
myPaint.setColor(0xffff0000); //color.RED
canvas.drawLine(myArrayListOfValues.get(i), myArrayListOfValues.get(i), myArrayListOfValues.get(i-1), myArrayListOfValues.get(i-1), myPaint);
}
Another thing is..my lines and circles that I draw are ALWAYS black.. setColor() never seems to have any effect. I've tried using the color names (e.g color.red) and even their hex values (e.g 0xffff0000)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果删除 ANTI_ALIAS_FLAG 会发生什么?另外,您应该将 Paint 构造函数移到 for 循环之外,这样就不会每次迭代都重新创建它。
What happens if you remove the ANTI_ALIAS_FLAG? Also, you should move the Paint constructor outside the for loop, so it doesn't get recreated every iteration.
试试这个(科特林)
Try this(kotlin)
将 的值更改
为更大的整数,例如:
它会使线条更粗
另请参阅 Paint.setStrokeWidth(float)
Change the value of
to a bigger integer, for instance:
it will make the line thicker
see also Paint.setStrokeWidth(float)
尝试在声明“mypaint”后立即包含此行
Try Including this line just after you decleare 'mypaint'