Android canvas画线-让线条变粗

发布于 2024-11-26 03:08:28 字数 641 浏览 1 评论 0原文

这看起来应该有点微不足道,但是在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绝不放开 2024-12-03 03:08:29

如果删除 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.

倦话 2024-12-03 03:08:29

试试这个(科特林)

myPaint.apply{
            isAntiAlias = true
            color = Color.BLACK
            style = Paint.Style.STROKE
            strokeWidth = 5.dp
        }

Try this(kotlin)

myPaint.apply{
            isAntiAlias = true
            color = Color.BLACK
            style = Paint.Style.STROKE
            strokeWidth = 5.dp
        }
时光匆匆的小流年 2024-12-03 03:08:28

将 的值更改

myPaint.setStrokeWidth(8);

为更大的整数,例如:

myPaint.setStrokeWidth(50);

它会使线条更粗

另请参阅 Paint.setStrokeWidth(float)

Change the value of

myPaint.setStrokeWidth(8);

to a bigger integer, for instance:

myPaint.setStrokeWidth(50);

it will make the line thicker

see also Paint.setStrokeWidth(float)

一场信仰旅途 2024-12-03 03:08:28

尝试在声明“mypaint”后立即包含此行

 mypaint.setStyle(Paint.Style.STROKE); 

Try Including this line just after you decleare 'mypaint'

 mypaint.setStyle(Paint.Style.STROKE); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文