private fun getSpin() {
val angle = Random.nextInt(3600 - 360) + 360
val pivotX: Float = image_rotate.width / 2f // всегда 0
val pivotY: Float = image_rotate.height / 2f // всегда 0
Log.d("ImageHeight", image_rotate.height.toString())
Log.d("ImageWidth", image_rotate.width.toString())
img_btn_flop.setOnClickListener {
val rotateAnimation = RotateAnimation(
(if (lastAngle == -1) 0 else lastAngle).toFloat(),
angle.toFloat(),
pivotX,
pivotY
)
lastAngle = angle
rotateAnimation.duration = 1100
rotateAnimation.fillAfter = true
image_rotate.startAnimation(rotateAnimation)
img_btn_flop.isEnabled = false
}
}
Я пишу анимацию вращения и дял этого у меня есть 2 строчки, которые делят ширину и высоту на 2, но при этом ширина и высота всегда приходит 0. С чем это может быть связано? Может ли это быть связано с тем, что я не вызываю findViewById в методе onCreateView, а напрямую обращаюсь к xml разметке?
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:src="@drawable/background"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</ImageView>
<ImageButton
android:id="@+id/img_btn_flop"
android:layout_width="229dp"
android:layout_height="97dp"
android:layout_marginBottom="40dp"
android:background="@null"
android:src="@drawable/flop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="@+id/image_rotate"
android:layout_width="320dp"
android:layout_height="320dp"
android:layout_centerInParent="true"
android:src="@drawable/wheel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/image_stop"
android:layout_width="60dp"
android:layout_height="70dp"
android:layout_marginBottom="20dp"
android:src="@drawable/stop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Я уже пробовал инициализировать ширину и высоту в onCreateView, но это не помогло и все равно ширина и высота равна 0.