Untitled
unknown
kotlin
2 years ago
1.7 kB
7
Indexable
import android.animation.Animator import android.animation.AnimatorListenerAdapter import android.os.Bundle import android.view.View import androidx.appcompat.app.AppCompatActivity import kotlinx.android.synthetic.main.activity_main.* // Import your layout's elements class MainActivity : AppCompatActivity() { private var isLayoutVisible = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Toggle the layout visibility when a button is clicked (you can use any trigger) toggleButton.setOnClickListener { if (isLayoutVisible) { hideLayout() } else { showLayout() } } } private fun showLayout() { animatedLayout.visibility = View.VISIBLE animatedLayout.alpha = 0f animatedLayout.animate() .alpha(1f) .setDuration(500) // Duration of the animation in milliseconds .setListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { // Animation finished } }) isLayoutVisible = true } private fun hideLayout() { animatedLayout.animate() .alpha(0f) .setDuration(500) // Duration of the animation in milliseconds .setListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { animatedLayout.visibility = View.GONE } }) isLayoutVisible = false } }
Editor is loading...