Arc menu 2 (animation gradually) Kotlin development (with java source code), kotlinjava

Source: Internet
Author: User

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 )...

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.