Junior
Чӣ гуна бояд кард, ки объектҳо дар тарҳ дар шакли давра ҷойгир шаванд?
sobes.tech AI
Ҷавоб аз AI
Барои ҷойгир кардани объектҳо дар давра метавонед ConstraintLayout бо 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="Марказ"
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="Тугма 1"
app:layout_constraintCircle="@+id/center_view" // ID-и унсури марказӣ
app:layout_constraintCircleRadius="150dp" // Радиуси давра
app:layout_constraintCircleAngle="0" /> // Ҳуҷуми дараҷа (0° - рост)
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Тугма 2"
app:layout_constraintCircle="@+id/center_view"
app:layout_constraintCircleRadius="150dp"
app:layout_constraintCircleAngle="90" /> // 90° - поён
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Тугма 3"
app:layout_constraintCircle="@+id/center_view"
app:layout_constraintCircleRadius="150dp"
app:layout_constraintCircleAngle="180" /> // 180° - чап
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Тугма 4"
app:layout_constraintCircle="@+id/center_view"
app:layout_constraintCircleRadius="150dp"
app:layout_constraintCircleAngle="270" /> // 270° - боло
</androidx.constraintlayout.widget.ConstraintLayout>
Атрибутҳо барои ҷойгиркунии давра:
| Атрибут | Тавсиф |
|---|---|
app:layout_constraintCircle |
ID-и унсури, ки атрофи он давра сохта мешавад. |
app:layout_constraintCircleRadius |
Радиуси давра дар dp. |
app:layout_constraintCircleAngle |
Ҳуҷуми дараҷа (0° - рост аз марказ, меафзояд дар муқобили соат). |