1

我想在地图上手动绘制箭头。我没有使用可绘制对象的旋转来解决性能问题,因为如果使用这种技术进行绘制,我有许多叠加层会减慢应用程序的速度。

我将手动绘制箭头,给定一个 gps 点和旋转角度,我需要在该点上绘制箭头。我将扩展覆盖类并在绘制方法上,我将完成绘图工作。

有什么建议么 ?

4

1 回答 1

0

我在我的应用程序中处理了同样的问题。代码在github上

基本上我draw在绘制箭头之前覆盖并旋转画布。

@Override
public void draw(Canvas canvas) {

    //NOTE: 0, 0 is the bottom center point of the bus icon

    //first draw the bus
    vehicle.draw(canvas);

    //then draw arrow
    if (arrow != null && heading != BusLocation.NO_HEADING)
    {
        //put the arrow in the bus window

        int arrowLeft = -(arrow.getIntrinsicWidth() / 4);
        int arrowTop = -vehicle.getIntrinsicHeight() + arrowTopDiff;

        //NOTE: use integer division when possible. This code is frequently executed
        int arrowWidth = (arrow.getIntrinsicWidth() * 6) / 10;  
        int arrowHeight = (arrow.getIntrinsicHeight() * 6) / 10;
        int arrowRight = arrowLeft + arrowWidth;
        int arrowBottom = arrowTop + arrowHeight;

        arrow.setBounds(arrowLeft, arrowTop, arrowRight, arrowBottom);

        canvas.save();
        //set rotation pivot at the center of the arrow image
        canvas.rotate(heading, arrowLeft + arrowWidth/2, arrowTop + arrowHeight / 2);

        Rect rect = arrow.getBounds();
        arrow.draw(canvas);
        arrow.setBounds(rect);

        canvas.restore();

    }

}
于 2012-10-18T11:19:04.427 回答