Skip to content

Instantly share code, notes, and snippets.

@omidMirrajei
Last active December 5, 2019 23:46
Show Gist options
  • Save omidMirrajei/c9e8fa439ecfbe02647f0ee01e4f9dea to your computer and use it in GitHub Desktop.
Save omidMirrajei/c9e8fa439ecfbe02647f0ee01e4f9dea to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val initialTextViewTranY = textView_progress.translationY
seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
textView_progress.text = progress.toString()
val translationDistance = (initialTextViewTranY +
progress * resources.getDimension(R.dimen.text_anim_stem) * -1)
textView_progress.animate().translationY(translationDistance)
if (!fromUser)
textView_progress.animate().setDuration(500).rotationBy(360f)
.translationY(initialTextViewTranY)
}
override fun onStartTrackingTouch(seekBar: SeekBar?)
override fun onStopTrackingTouch(seekBar: SeekBar?)
})
button_reset.setOnClickListener { seekBar.progress = 0 }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment