Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android Kotlin中绘制螺旋视图_Android_Kotlin - Fatal编程技术网

在android Kotlin中绘制螺旋视图

在android Kotlin中绘制螺旋视图,android,kotlin,Android,Kotlin,我正在尝试绘制螺旋视图,如所附屏幕截图所示, 我有一系列的点来绘制基于圆圈上的数字。 我是android和kotlin的新手 有人能建议怎么做吗 今天,我将螺旋图添加到我正在构建的自定义滚动形状应用程序中。我的实现使用Androidimport Android.graphics.Path。螺旋图形基于用户滚动,用户滚动时添加更多的线段 这个解决方案的要点如下:我从一个初始弧开始,画出它。该圆弧是螺旋的初始圆弧。在该圆弧已添加到路径上时,使用路径的边界矩形确定圆弧下一段的边界 以下是一个示例,但对

我正在尝试绘制螺旋视图,如所附屏幕截图所示, 我有一系列的点来绘制基于圆圈上的数字。 我是android和kotlin的新手

有人能建议怎么做吗


今天,我将螺旋图添加到我正在构建的自定义滚动形状应用程序中。我的实现使用Android
import Android.graphics.Path。螺旋图形基于用户滚动,用户滚动时添加更多的线段

这个解决方案的要点如下:我从一个初始弧开始,画出它。该圆弧是螺旋的初始圆弧。在该圆弧已添加到路径上时,使用路径的边界矩形确定圆弧下一段的边界

以下是一个示例,但对于完整的上下文,您需要查看项目:


谢谢你的链接,它工作得很好。我想给螺旋动画,你能告诉我怎么做吗?
         private void addTopSpiralSegment(Path path, RectF bounds, SpiralSegment spiralSegment) {
                float centerX = bounds.centerX();
                float centerY = bounds.centerY();

                float segmentBoundsLeft;
                float segmentBoundsRight;
                float segmentBoundsTop;
                float segmentBoundsBottom;

                if (path.isEmpty()) {
                    segmentBoundsLeft = centerX - spiralSegment.getWidth() / 2;
                    segmentBoundsRight = centerX + spiralSegment.getWidth() / 2;
                    segmentBoundsTop = centerY - spiralSegment.getHeight() / 2;
                    segmentBoundsBottom = centerY + spiralSegment.getHeight() / 2;
                } else {
                    RectF pathBounds = new RectF();
                    path.computeBounds(pathBounds, true);

                    segmentBoundsLeft = pathBounds.left;
                    segmentBoundsRight = segmentBoundsLeft + spiralSegment.getWidth();
                    segmentBoundsTop = centerY - spiralSegment.getHeight() / 2;
                    segmentBoundsBottom = centerY + spiralSegment.getHeight() / 2;
                }

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    path.addArc(segmentBoundsLeft, segmentBoundsTop, segmentBoundsRight,
                            segmentBoundsBottom, 180, 180);
                }
            }

    private void addBottomSpiralSegment(Path path, RectF bounds, SpiralSegment spiralSegment) {
            float centerX = bounds.centerX();
            float centerY = bounds.centerY();

            float segmentBoundsLeft;
            float segmentBoundsRight;
            float segmentBoundsTop;
            float segmentBoundsBottom;

            if (path.isEmpty()) {
                segmentBoundsLeft = centerX - spiralSegment.getWidth() / 2;
                segmentBoundsRight = centerX + spiralSegment.getWidth() / 2;
                segmentBoundsTop = centerY - spiralSegment.getHeight() / 2;
                segmentBoundsBottom = centerY + spiralSegment.getHeight() / 2;
            } else {
                RectF pathBounds = new RectF();
                path.computeBounds(pathBounds, true);

                segmentBoundsLeft = pathBounds.right - spiralSegment.getWidth();
                segmentBoundsRight = pathBounds.right;
                segmentBoundsTop = centerY - spiralSegment.getHeight() / 2;
                segmentBoundsBottom = centerY + spiralSegment.getHeight() / 2;
            }

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                path.addArc(segmentBoundsLeft, segmentBoundsTop, segmentBoundsRight,
                        segmentBoundsBottom, 0, 180);
            }
        }