Junior
Jak zajistit, aby se objekty v rozložení umístily do kruhu?
sobes.tech AI
Odpověď od AI
Pro rozložení objektů do kruhu můžete použít ConstraintLayout s Circular positioning.
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/center_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Střed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tlačítko 1"
app:layout_constraintCircle="@+id/center_view" // ID centrálního prvku
app:layout_constraintCircleRadius="150dp" // Poloměr kruhu
app:layout_constraintCircleAngle="0" /> // Úhel ve stupních (0° - vpravo)
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tlačítko 2"
app:layout_constraintCircle="@+id/center_view"
app:layout_constraintCircleRadius="150dp"
app:layout_constraintCircleAngle="90" /> // 90° - dole
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tlačítko 3"
app:layout_constraintCircle="@+id/center_view"
app:layout_constraintCircleRadius="150dp"
app:layout_constraintCircleAngle="180" /> // 180° - vlevo
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tlačítko 4"
app:layout_constraintCircle="@+id/center_view"
app:layout_constraintCircleRadius="150dp"
app:layout_constraintCircleAngle="270" /> // 270° - nahoře
</androidx.constraintlayout.widget.ConstraintLayout>
Atributy pro kruhové umístění:
| Atribut | Popis |
|---|---|
app:layout_constraintCircle |
ID prvku, kolem kterého se kruh staví. |
app:layout_constraintCircleRadius |
Poloměr kruhu v dp. |
app:layout_constraintCircleAngle |
Úhel ve stupních (0° - vpravo od středu, zvyšuje se proti směru hodinových ručiček). |