Arc Menu 2 (animation fade in) Kotlin development (with Java source code)

Source: Internet
Author: User

Arc Menu 2 (animation fade-in +kotlin development)

Preface: A curved menu based on Androidstudio, which is developed using the Kotlin language, and the animation is gradually entered ...

Effect:

Development environment: androidstudio2.2.1+gradle-2.14.1

Knowledge Involved: 1. Custom controls, 2. Event distribution, etc.

Part of the code:

Activity:

classhomepageactivity:appcompatactivity () {Privatevar homepagemenulayout:homepagemenulayout? =NULLOverride Fun OnCreate (Savedinstancestate:bundle?) {        Super. OnCreate (savedinstancestate) Setcontentview (r.layout.homepage_layout) initlayout ()}PrivateFun initlayout () {homepagemenulayout=Findviewbyid (r.id.homepage_layout) as Homepagemenulayout//load Menu Listhomepagemenulayout!!. Setmenuitemiconsandtexts (Constants.menuall)//just dot animation initialSwitchanimationutil (). Startanimation (homepagemenulayout!!, SwitchAnimationUtil.AnimationType.ROTATE)//Event Monitoringhomepagemenulayout!!. Setonmenuitemclicklistener (Object:HomePageMenuLayout.OnMenuItemClickListener {override fun ItemClick (vi Ew:view, Pos:int) {Toast.maketext ( This@HomepageActivity, Constants.menuall[pos], Toast.length_short). Show ()})}}

Animation class:

/*** Menu Animation loading class*/classSwitchanimationutil {Privatevar morderindex = 0PrivateVal Mdelay = 80PrivateVal mduration = 500Fun startanimation (Root:view, Type:animationtype) {bindanimation (root,0, type)} PrivateFun 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++        }    }    PrivateFun runanimation (View:view, Delay:long, Type:animationtype) {when (type) {Switchanimationutil. Animationtype.rotate-runrotateanimation (view, delay) SwitchAnimationUtil.AnimationType.ALPHA-runalphaanimation (view, delay)Else- {            }        }    }    PrivateFun 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 ()}PrivateFun 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 classAnimationtype {ALPHA, ROTATE}}

SOURCE Download 1 (Kotlin version) ...

SOURCE Download 2 (Java version) ...

Arc Menu 2 (animation fade in) Kotlin development (with Java source code)

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.