ShapeDrawable(来自 PathShape)未在正确的坐标上绘制

发布于 2025-01-02 01:36:32 字数 649 浏览 2 评论 0原文

我正在尝试创建一个绘制以下路径的 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 技术交流群。

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

发布评论

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

评论(1

倾城花音 2025-01-09 01:36:32

在定义 PathShape 时,“someNumber”属性实际上非常重要,而且并不简单。它们是路径的“标准”宽度和高度,本质上定义了路径的边界,并与您定义路径的坐标直接相关,如 PathShape 构造函数 此处

另一个重要的一点是,就 PathShape 而言,用于定义 Path 的坐标不是绝对坐标,而是与标准宽度和高度相结合计算缩放后形状的外观。例如,以下两个 PathShape 本质上是相同的。

public Path getPath1 {
    Path path = new Path();
    path.lineTo(0, 1);
    path.lineTo(1, 0);
    path.close();
    return path;
}

public Path getPath2 {
    Path path = new Path();
    path.lineTo(0, 10);
    path.lineTo(5, 0);
    path.close();
    return path;
}

PathShape shape1 = new PathShape(getPath1(), 1, 1);
PathShape shape2 = new PathShape(getPath2(), 5, 10);

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 the PathShape constructor here.

Another important point is that the coordinates you use to define your Path are not absolute coordinates as far as a PathShape 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 two PathShapes are essentially identical.

public Path getPath1 {
    Path path = new Path();
    path.lineTo(0, 1);
    path.lineTo(1, 0);
    path.close();
    return path;
}

public Path getPath2 {
    Path path = new Path();
    path.lineTo(0, 10);
    path.lineTo(5, 0);
    path.close();
    return path;
}

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