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)