java - 自定义 Circlular seek arc 以将位图放置在给定的进度级别

标签 java android geometry drawing android-bitmap

当前

enter image description here

预计

enter image description here 我希望获得比图片中更好的结果, 情况。 给定一个进度值 X,我想获得进度的 x 和 y 坐标,以便我可以在 circular seekarc 周围绘制一个标志。 .

    for (int i = 0; i < positionList.size(); i++) {

        xPost = (float)(mArcRect.centerX() + mArcRadius* Math.cos(Math.toRadians(calculatePointerAngle((positionList.get(i).getPosition()+270)))));
        yPost = (float) (mArcRect.centerY() + mArcRadius * Math.sin(Math.toRadians(calculatePointerAngle((positionList.get(i).getPosition()+270)))));


        setflagX(xPost);
        setflagxY(yPost);
        points.add(new Points(xPost, yPost));


        // }
    }

然后我使用自定义类来绘制标志

..... `

 @Override
      public void onDraw(Canvas canvas) {
        //Draw the flag

    final Resources res = getResources();

// while (coordinates.iterator().hasNext()){
for (int i = 0; i < coordinates.size(); i++) {
    if (i == 0) {

        bm = BitmapFactory.decodeResource(res, R.drawable.ic_flag_red);

        canvas.drawBitmap(bm, coordinates.get(i).getX(),      coordinates.get(i).getY(), null);
        } else {

            bm = BitmapFactory.decodeResource(res, R.drawable.ic_flag_blue);

            canvas.drawBitmap(bm, coordinates.get(i).getX(), coordinates.get(i).getY(), null);

        }
    }



}`

任何关于如何修复偏移量的建议......我对圆外的点 bing 没问题

最佳答案

在我看来你做的是正确的,但是你画错了位图。

位图从 (left, top) 绘制到 (left + width, right + height) 而你没有考虑到这一点。

canvas.drawBitmap(bm, 
    coordinates.get(i).getX() - bm.getWidth() / 2,
    coordinates.get(i).getY() - bm.getHeight() / 2, null);

应该可以解决你的问题

关于java - 自定义 Circlular seek arc 以将位图放置在给定的进度级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33598492/

相关文章:

jquery - 用 css 和 jquery 将 html 元素排列成圆形

java - 为什么在这个例子中 Gradle 编译失败?

Java认证/授权服务器

java - 为什么我来自 Android 的 UDP 消息不起作用?

android - EditText 制表符顺序

math - 查找垂直点与直线相交处的 x 和 y 坐标

algorithm - 多边形中的孔

Java作业-从我的计算中得到一些奇怪的值

java - 用 Java 表示货币值(value)

java - Android 中的运动检测器