How are you supposed to use a ShapeDrawable with a PathShape to draw a line on a custom View?

岁酱吖の 提交于 2019-12-03 16:09:09
Daniel

There are two issues with this.

The first is the Paint style. The default is Paint.Stroke.FILL, but with a line there's nothing to fill. I needed to add this (thanks, Romain Guy):

this.mPaint.setStyle(Paint.Style.STROKE);

The second issue is that the standard height and width in the PathShape is not correct. I had read the documentation on this, but did not understand it correctly. This became apparent once I fixed the first issue. Setting it to the height and width of my custom view (since I am drawing across the whole view) fixed this. I also had to change the bounds of the ShapeDrawable to match.

this.mPathShape = new PathShape(this.mPath, this.getWidth(), this.getHeight());

and

this.mShapeDrawable.setBounds(0, 0, this.getWidth(), this.getHeight());

Hopefully this helps someone else in the future.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!