안드로이드 개발 질문/답변
(글 수 45,052)
룰렛를 구현중인데요
룰렛에 당첨이 되었을 때 그 당첨된 항목을 토스트로 뿌려주려고 합니다.
하지만 그 당첨된 룰렛의 값을 어찌 가져와야 할지 모르겠네요
private void drawRoulette(Canvas canvas) { int centerX = this.getWidth() / 2; int centerY = this.getHeight() / 2; int roulWidth = this.getWidth() - 10; //int roulHeight = roulWidth; int radius = roulWidth / 2; RectF rt = new RectF(centerX-radius, centerY-radius, centerX+radius, centerY+radius); float SliceAngle = 360.0f / mSlices.size(); double textStartX = radius - 8; double textStartY = 0.0; //int PrevColorIdx = -1; int CurColorIdx = -1; for(int i=0; i<mSlices.size(); startAngle+=SliceAngle, i++) { // do { // CurColorIdx = Rnd.nextInt(ColorList.length); // } while(CurColorIdx == PrevColorIdx); CurColorIdx = i%ColorList.length; Pnt.setColor(ColorList[CurColorIdx]); Pnt.setStyle(Paint.Style.FILL); canvas.drawArc(rt, startAngle, SliceAngle, true, Pnt); float curHalfAngle = (startAngle + (SliceAngle / 2)); // x' = x * cosθ + y * (-sinθ) double txtStartX = Math.cos(Math.toRadians(curHalfAngle)) * textStartX; txtStartX = txtStartX + Math.sin(Math.toRadians(curHalfAngle)) * textStartY * (-1); txtStartX += centerX; // y' = x * sinθ + y * cosθ double txtStartY= Math.sin(Math.toRadians(curHalfAngle)) * textStartX; txtStartY = txtStartY + Math.cos(Math.toRadians(curHalfAngle)) * textStartY; txtStartY += centerY; textPath.reset(); Pnt.setColor(Color.WHITE); Pnt.setStrokeWidth(3); textPath.moveTo((int)txtStartX, (int)txtStartY); textPath.lineTo(centerX, centerY); canvas.drawTextOnPath(mSlices.get(i), textPath, 0, 0, Pnt); } textPath.reset(); textPath.moveTo(centerX, centerY - radius + 15); textPath.lineTo(centerX + 10, centerY - radius - 15); textPath.lineTo(centerX - 10, centerY - radius - 15); textPath.lineTo(centerX, centerY - radius + 15); Pnt.setStrokeWidth(1); Pnt.setColor(0xFF555555); canvas.drawPath(textPath, Pnt); }
이런식으로 canvas로 부채꼴를 그리고 거기에 글씨를 써넣는 방식으로 구현했습니다.
여기서 어떻게 하면 당첨된 항목을 가져올수 있을까요?
아 정말 힘드네요 ㅜㅜ