Sobes.tech
Junior

Ako zabezpečiť, aby sa objekty v rozložení rozmiestnili do kruhu?

sobes.tech AI

Odpoveď od AI

Pre rozmiestnenie objektov do kruhu môžete použiť 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="Stred"
        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čidlo 1"
        app:layout_constraintCircle="@+id/center_view" // ID centrálneho prvku
        app:layout_constraintCircleRadius="150dp" // Polomer kruhu
        app:layout_constraintCircleAngle="0" /> // Uhol v stupňoch (0° - vpravo)

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Tlačidlo 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čidlo 3"
        app:layout_constraintCircle="@+id/center_view"
        app:layout_constraintCircleRadius="150dp"
        app:layout_constraintCircleAngle="180" /> // 180° - vľavo

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Tlačidlo 4"
        app:layout_constraintCircle="@+id/center_view"
        app:layout_constraintCircleRadius="150dp"
        app:layout_constraintCircleAngle="270" /> // 270° - hore

</androidx.constraintlayout.widget.ConstraintLayout>

Atribúty pre kruhové umiestnenie:

Atribút Popis
app:layout_constraintCircle ID prvku, okolo ktorého sa kruh vytvára.
app:layout_constraintCircleRadius Polomer kruhu v dp.
app:layout_constraintCircleAngle Uhol v stupňoch (0° - vpravo od stredu, zvyšuje sa proti smeru hodinových ručičiek).