How i generate squentially from the random imageView.
i need make generator from button roll but the result is squentially dice number in format image? this for 2D dice,
please help and thank you very much
sorry may bad english
package com.example.dice
import android.os.Bundle
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.Button
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import kotlin.random.Random
class MainActivity : AppCompatActivity() {
private lateinit var imgDice: ImageView
private val diceImages: MutableList<Int> = mutableListOf()
private lateinit var animation: Animation
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
imgDice = findViewById(R.id.imgDice)
val btnRoll = findViewById<Button>(R.id.btnRoll)
btnRoll.setOnClickListener {
getRandomValue()
}
diceImages.add(R.drawable.dice1)
diceImages.add(R.drawable.dice2)
diceImages.add(R.drawable.dice3)
diceImages.add(R.drawable.dice4)
diceImages.add(R.drawable.dice5)
diceImages.add(R.drawable.dice6)
animation = AnimationUtils.loadAnimation(this@MainActivity, R.anim.shake_anim)
}
private fun getRandomValue() {
val random = Random().nextInt(6)
imgDice.setImageResource(diceImages.elementAt(random))
animation.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationRepeat(animation: Animation?) {
imgDice.startAnimation(animation)
}
override fun onAnimationEnd(animation: Animation?) { imgDice.setImageResource(diceImages.elementAt(random))
}
override fun onAnimationStart(animation: Animation?) {
imgDice.setImageResource(R.drawable.dice1)
}
})
}
}
question from:
https://stackoverflow.com/questions/65840015/how-to-generate-from-random-image-imageview-to-be-unrandom-squentially-kotlin 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…