뷰를 원형으로 배치
▼완성형▼
1. 둥근 View 만들기
우선은 색이 붙은 둥근 View를 만듭니다.
둥근 View의 작성 방법에 대해서는, 이하의 기사가 참고가 된다고 생각합니다.
색이 있는 둥근 View 만들기
가운데에 있는 빨간색 View의 모양 드로와블만 기재합니다만, <solid android:color="" />
를 변경하면, 다른 색에도 적용할 수 있습니다.
res/drawable/shape_red_icon.xml<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Viewの角を丸くする -->
<corners android:radius="15dp" />
<!-- Viewの色を指定する -->
<solid android:color="#ef9a9a" />
</shape>
2. View를 원형으로 배치
뷰를 원형으로 배치할 때 루트를 ConstraintLayout
로 설정하고 다음 속성을 지정합니다.
layout_constraintCircle
중심이 될 View의 ID를 지정합니다.
layout_constraintCircleAngle
layout_constraintCircle
에서 지정한 View를 기점으로 원형으로 배치할 View의 "각도(0~360)"를 지정합니다.
시계에 비유하면 「0->12시, 30->1시, 60->2시」의 위치가 됩니다.
layout_constraintCircleRadius
layout_constraintCircle
에 지정된 View의 반경을 지정합니다.
레이아웃은 다음과 같습니다.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<View
android:id="@+id/red_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_red_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/pink_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_pink_icon"
app:layout_constraintBottom_toTopOf="@+id/red_circle_view"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="0"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/purple_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_purple_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="30"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/deep_purple_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_deep_purple_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="60"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/indigo_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_indigo_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="90"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/blue_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_blue_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="120"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/light_blue_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_light_blue_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="150"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/cyan_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_cyan_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="180"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/teal_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_teal_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="210"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/green_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_green_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="240"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/light_green_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_light_green_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="270"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/lime_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_lime_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="300"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/yellow_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_yellow_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="330"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
이것으로 완성입니다.
Reference
이 문제에 관하여(뷰를 원형으로 배치), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/yass97/items/b3553f1926b6fabc0278
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Viewの角を丸くする -->
<corners android:radius="15dp" />
<!-- Viewの色を指定する -->
<solid android:color="#ef9a9a" />
</shape>
뷰를 원형으로 배치할 때 루트를
ConstraintLayout
로 설정하고 다음 속성을 지정합니다.layout_constraintCircle
중심이 될 View의 ID를 지정합니다.
layout_constraintCircleAngle
layout_constraintCircle
에서 지정한 View를 기점으로 원형으로 배치할 View의 "각도(0~360)"를 지정합니다.시계에 비유하면 「0->12시, 30->1시, 60->2시」의 위치가 됩니다.
layout_constraintCircleRadius
layout_constraintCircle
에 지정된 View의 반경을 지정합니다.레이아웃은 다음과 같습니다.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<View
android:id="@+id/red_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_red_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/pink_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_pink_icon"
app:layout_constraintBottom_toTopOf="@+id/red_circle_view"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="0"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/purple_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_purple_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="30"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/deep_purple_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_deep_purple_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="60"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/indigo_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_indigo_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="90"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/blue_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_blue_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="120"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/light_blue_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_light_blue_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="150"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/cyan_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_cyan_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="180"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/teal_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_teal_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="210"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/green_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_green_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="240"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/light_green_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_light_green_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="270"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/lime_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_lime_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="300"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/yellow_circle_view"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/shape_yellow_icon"
app:layout_constraintCircle="@id/red_circle_view"
app:layout_constraintCircleAngle="330"
app:layout_constraintCircleRadius="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
이것으로 완성입니다.
Reference
이 문제에 관하여(뷰를 원형으로 배치), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/yass97/items/b3553f1926b6fabc0278텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)