필자는 4 개의 동심원 (원한다면 레이더 효과)을 포함하려는 RelativeLayout을 가지고 있습니다. RelativeLayout을 숨기고 표시하고 싶습니다. 그래서 Canvas와 Paint를 사용하여 정확히 어떻게 RelativeLayout에 원을 그리는 지 궁금합니다. 누군가가 작동하는 방법의 수명주기를 설명 할 수 있다면 매우 유용 할 것입니다. 지금 당장 :Android : 기본 원형 개요를 RelativeLayout에 그리기
setContentView(R.layout.applayout);
myRelLayout = (RelativeLayout) findViewById(R.id.RLRadar);
Canvas canvas = new Canvas();
Paint circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setColor(0xFF000000);
circlePaint.setStyle(Style.STROKE);
canvas.drawCircle((float) centerX, (float) centerY, (float) (maxRadius/4), circlePaint);
나는 올바른 길을 가고 있습니까? 캔버스를 일종의 ImageView로 변환하여 RelativeLayout에 추가해야합니까? 아니면 여기서 완전히 벗어나지?
도움 주셔서 감사합니다.
편집 : 다음은 작동 코드입니다.
// Add the radar to the RadarRL
Picture picture = new Picture();
Canvas canvas = picture.beginRecording(screenWidth, screenHeight);
// Draw on the canvas
Paint circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setColor(0xFF000000);
circlePaint.setStyle(Style.STROKE);
circlePaint.setStrokeWidth((float) 5.0);
canvas.drawCircle((float) centerX, (float) centerY, (float) (maxRadius/4), circlePaint);
canvas.drawCircle((float) centerX, (float) centerY, (float) ((3 * maxRadius)/4), circlePaint);
canvas.drawCircle((float) centerX, (float) centerY, (float) (maxRadius/2), circlePaint);
canvas.drawCircle((float) centerX, (float) centerY, (float) (maxRadius), circlePaint);
picture.endRecording();
안녕하세요 팀, 내가이 구현하지만, 아무것도 내 RelativeLayout의에 표시되지 않습니다했습니다. 내가 사용한 코드로 원래 게시물을 편집했습니다. 내가 잘못한 것을 확인할 수 있니? – Rockmaninoff
Nevermind가 작동했습니다! – Rockmaninoff
'setBackgroundDrawable'은 더 이상 사용되지 않습니다. –