ShapeDrawable(从PathShape)没有吸取正确的坐标 [英] ShapeDrawable(from a PathShape) not drawing on correct coordinates

查看:135
本文介绍了ShapeDrawable(从PathShape)没有吸取正确的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建得出如下路径ShapeDrawable:

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 ));

然后我把shapeDrawable作为一个图层绘制的,像这样的顶层:

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);

现在的问题是,路径不为(50,20)开始,它跳跃的方式围绕当你改变我不明白 somenumber 其中shapeDrawable构造。

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.

任何帮助或文档,你可以建议的是AP preciated。

Any help or documentation that you can suggest is appreciated.

推荐答案

定义当你的 PathShape 的someNumber属性实际上是非常重要的,是不平凡的。他们是路径的标准的宽度和高度,基本上是定义路径的边界,并直接与坐标你作为 PathShape 构造<指定的定义路径HREF =htt​​p://developer.android.com/reference/android/graphics/drawable/shapes/PathShape.html相对=nofollow>这里。

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.

另外重要的一点是,坐标用来定义你的路径是尽可能在 PathShape 而言,而是与标准的宽度和高度结合起来,计算时进行缩放你的图形的显示方式。例如,下面的两个 PathShape 是基本相同的。

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);

这篇关于ShapeDrawable(从PathShape)没有吸取正确的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆