Arc menu 2 (animation gradually) Kotlin development (with java source code), kotlinjava
Arc menu 2 (Animated gradually + Kotlin Development)
The arc menu of animations developed in the Kotlin language based on AndroidStudio is ......
Effect:
Development Environment: AndroidStudio2.2.1 + gradle-2.14.1
Knowledge: 1. Custom Controls, 2. Event distribution, etc.
Some code:
Activity:
Class HomepageActivity: AppCompatActivity () {private var homePageMenuLayout: HomePageMenuLayout? = Null override fun onCreate (savedInstanceState: Bundle ?) {Super. onCreate (savedInstanceState) setContentView (R. layout. homepage_layout) initLayout ()} private fun initLayout () {homePageMenuLayout = findViewById (R. id. homepage_layout) as HomePageMenuLayout // load the menu list homePageMenuLayout !!. SetMenuItemIconsAndTexts (Constants. MENUALL) // click the initial SwitchAnimationUtil (). startAnimation (homePageMenuLayout !!, SwitchAnimationUtil. AnimationType. ROTATE) // event listening homePageMenuLayout !!. SetOnMenuItemClickListener (object: HomePageMenuLayout. onMenuItemClickListener {override fun itemClick (view: View, pos: Int) {Toast. makeText (this @ HomepageActivity, Constants. MENUALL [pos], Toast. LENGTH_SHORT ). show ()}})}}
Animation:
/*** Menu animation loading class */class SwitchAnimationUtil {private var mOrderIndex = 0 private val mDelay = 80 private val mDuration = 500 fun startAnimation (root: View, type: AnimationType) {bindAnimation (root, 0, type)} private fun bindAnimation (view: View, depth: Int, type: AnimationType) {if (view is ViewGroup) {val group = view for (I in 0 .. group. childCount-1) {bindAnimation (group. getChildAt (I), depth + 1, type)} else {runAnimation (view, (mDelay * mOrderIndex ). toLong (), type) mOrderIndex ++} private fun runAnimation (view: View, delay: Long, type: AnimationType) {when (type) {SwitchAnimationUtil. animationType. ROTATE-> runRotateAnimation (view, delay) SwitchAnimationUtil. animationType. ALPHA-> runAlphaAnimation (view, delay) else->{}} private fun runAlphaAnimation (view: View, delay: Long) {view. alpha = 0f val objectAnimator = ObjectAnimator. ofFloat (view, "alpha", 0f, 1f) objectAnimator. startDelay = delay objectAnimator. duration = mDuration. toLong () objectAnimator. interpolator = LinearInterpolator () objectAnimator. start ()} private fun runRotateAnimation (view: View, delay: Long) {view. alpha = 0f val set = AnimatorSet () val objectAnimator = ObjectAnimator. ofFloat (view, "rotation", 0f, 0f) val objectAnimator2 = ObjectAnimator. ofFloat (view, "scaleX", 0f, 1f) val objectAnimator3 = ObjectAnimator. ofFloat (view, "scaleY", 0f, 1f) val objectAnimator4 = ObjectAnimator. ofFloat (view, "alpha", 0f, 1f) objectAnimator2.interpolator = AccelerateInterpolator (1.0f) objectAnimator3.interpolator = AccelerateInterpolator (1.0f) set. duration = mDuration. toLong () set. playTogether (objectAnimator, objectAnimator2, objectAnimator3, objectAnimator4) set. startDelay = delay set. start ()} enum class AnimationType {ALPHA, ROTATE }}
Download source code 1 (Kotlin )...
Download source code 2 (Java version )...