ShapeDrawable(来自 PathShape)未在正确的坐标上绘制
我正在尝试创建一个绘制以下路径的 ShapeDrawable:
Path path = new Path();
path.moveTo(50, 20);
path.lineTo(0, 50);
path.lineTo(50, 100);
ShapeDrawable shapeDrawable = new ShapeDrawable(new PathShape(path, someNumber ,someNumber ));
然后我将 shapeDrawable 作为可绘制图层的顶层,如下所示:
Drawable layers[] = new Drawable[2];
layers[0] = res.getDrawable(R.drawable.crawford01);
layers[1] = shapeDrawable;
LayerDrawable layerDrawable = new LayerDrawable(layers);
view.setImageDrawable(layerDrawable);
现在的问题是路径不是从 (50,20) 开始,而是四处跳跃当您更改构建 shapeDrawable 的 somenumber
时,我不明白。
我们非常感谢您建议的任何帮助或文档。
I'm trying to create a ShapeDrawable that draws the following path:
Path path = new Path();
path.moveTo(50, 20);
path.lineTo(0, 50);
path.lineTo(50, 100);
ShapeDrawable shapeDrawable = new ShapeDrawable(new PathShape(path, someNumber ,someNumber ));
Then I put shapeDrawable as the top layer of a Layer drawable like so:
Drawable layers[] = new Drawable[2];
layers[0] = res.getDrawable(R.drawable.crawford01);
layers[1] = shapeDrawable;
LayerDrawable layerDrawable = new LayerDrawable(layers);
view.setImageDrawable(layerDrawable);
Now the problem is that the path doesn't start at (50,20) and it jumps around in ways I don't understand when you change somenumber
where shapeDrawable is constructed.
Any help or documentation that you can suggest is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在定义 PathShape 时,“someNumber”属性实际上非常重要,而且并不简单。它们是路径的“标准”宽度和高度,本质上定义了路径的边界,并与您定义路径的坐标直接相关,如
PathShape
构造函数 此处。另一个重要的一点是,就
PathShape
而言,用于定义Path
的坐标不是绝对坐标,而是与标准宽度和高度相结合计算缩放后形状的外观。例如,以下两个 PathShape 本质上是相同的。The "someNumber" attributes are actually very important when defining your
PathShape
, and are not trivial. They are the "standard" width and height of the path, essentially defining the path's bounds and relating directly to the coordinates you define your path at as specified in thePathShape
constructor here.Another important point is that the coordinates you use to define your
Path
are not absolute coordinates as far as aPathShape
is concerned, but instead is combined with the standard width and height to calculate how your shape appears when it is scaled. For example, the following twoPathShape
s are essentially identical.