Android's Custom multiple button view similar to Arcmenu (open source project on GitHub)

Source: Internet
Author: User

Recent projects have a relatively good open source of multiple sharing buttons of the custom view, feel better, so the study of the next, wrote down. In fact, this demo is similar to the open source project Arcmenu on GitHub, Project: Https://github.com/daCapricorn/ArcMenu.

Realize:


1, click the button, five buttons fly into the screen;

2. Click on one of the five buttons to change the button until it disappears, and the rest of the button becomes smaller until it disappears.

The experience is still very good.


Click the Five button again to fly out of the screen.


Okay, here's the source code. More, but are some of the custom space, see two times can understand it.


There is only one layout file: share_layout:

It defines the layout and buttons, which are custom layouts or buttons.

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" fill_parent "android:layout_height=" fill_parent "> <com.cu Stomview. Inoutrelativelayout android:id= "@+id/buttons_wrapper" android:layout_width= "Fill_parent" Android:layo ut_height= "Fill_parent" android:clipchildren= "false" android:cliptopadding= "false" > <!----&G        T <com.customview.inoutimagebutton android:id= "@+id/button_weixinfriends" android:layout_width= "46d IP "android:layout_height=" 46dip "android:layout_alignparentbottom=" true "Android:layout_            Marginbottom= "210dip" android:layout_marginleft= "30dip" android:background= "@drawable/weixin"            android:visibility= "Invisible"/> <!--Circle of friends and <com.customview.inoutimagebutton Android:id= "@+id/button_frIendsquan "android:layout_width=" 46dip "android:layout_height=" 46dip "Android:layout_alig            Nparentbottom= "true" android:layout_marginbottom= "190dip" android:layout_marginleft= "103dip"        android:background= "@drawable/friend_quan" android:visibility= "invisible"/> <!--Clear--             <com.customview.inoutimagebutton android:id= "@+id/button_clear" android:layout_width= "46dip" android:layout_height= "46dip" android:layout_alignparentbottom= "true" Android:layout_mar            Ginbottom= "127dip" android:layout_marginleft= "113dip" android:background= "@drawable/clear" android:visibility= "Invisible"/> <!--Reset-<com.customview.inoutimagebutton Android Oid:id= "@+id/button_reset" android:layout_width= "46dip" android:layout_height= "46dip" and Roid:layout_alignparentbOttom= "true" android:layout_marginbottom= "50dip" android:layout_marginleft= "97dip" Androi d:background= "@drawable/reset" android:visibility= "invisible"/> <!--screenshot--<com.cus Tomview. Inoutimagebutton android:id= "@+id/button_screenshot" android:layout_width= "46dip" Android            : layout_height= "46dip" android:layout_alignparentbottom= "true" android:layout_marginleft= "30dip" android:background= "@drawable/screenshot" android:visibility= "invisible"/> </com.customview.i        noutrelativelayout> <com.customview.inoutrelativelayout android:id= "@+id/button_control_show_hide" Android:layout_width= "60dip" android:layout_height= "60dip" android:layout_alignparentbottom= "true" an        Droid:layout_alignparentleft= "true" android:layout_marginbottom= "100dip" android:layout_marginleft= "20dip" Android:background= "@drawable/btn_selector" > <imageview android:id= "@+id/button_control_show_hide_icon" Android:layout_width= "60dip" android:layout_height= "60dip" android:layout_alignparentbottom= "True" android:layout_alignparentleft= "true" android:layout_marginbottom= "100dip" Android : layout_marginleft= "20dip" android:visibility= "visible"/> </com.customview.inoutrelativelayout>&lt ;/relativelayout>

The following is the main view interface Mainactivity class:

Both layout and trigger events are performed in this class.

Package Com.view;import Android.os.bundle;import Android.support.v7.app.actionbaractivity;import Android.view.View ; Import Android.view.view.onclicklistener;import Android.view.animation.animation;import Android.view.animation.animation.animationlistener;import Android.widget.toast;import Com.anim.abstractinoutanimationset.direction;import Com.anim.animationcontrolutils;import Com.anim.clickanimationset;import Com.anim.notclickanimationset;import Com.customview.inoutimagebutton;import com.customview.inoutrelativelayout;/** * Custom pop-in Popup button mainactivity * * @author Zhongyao */public class Mainactivity extends A ctionbaractivity {Private View mcontrolbutton;private boolean marebuttonsshowins;private inoutrelativelayout Mbuttonswrapper; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.share_layout);/** * Initialize Control */initshareview ();} /** * Initialize control */private void Initshareview () {Mcontrolbutton = Findviewbyid (r.id.button_control_show_Hide) Mcontrolbutton.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {/** * Eject retract switch */ ToggleButton ();}}); /All popup recall button View collection Mbuttonswrapper = (inoutrelativelayout) Findviewbyid (r.id.buttons_wrapper);//Set each popup recall button's Click event, Click to enlarge and hide for (int i = 0, count = Mbuttonswrapper.getchildcount (); I < count; i++) {if (Mbuttonswrapper.getchildat (i) INS Tanceof Inoutimagebutton) {View view = Mbuttonswrapper.getchildat (i); View.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View subject) {startbuttonclickanimations (subject);}});}}} /** * Eject retract switch */private void ToggleButton () {if (marebuttonsshowins) {//button eject Animationcontrolutils.startanimations ( Mbuttonswrapper,direction.out, 4);} else {//button bounces into Animationcontrolutils.startanimations (mbuttonswrapper,direction.in, 4);} Marebuttonsshowins =!marebuttonsshowins;} /** * Eject button click after animation (click the popup button to add animation) * * @param view */private void startbuttonclickanimations (view subject) {Marebuttonsshowin s = false;//Set animation for each button for (int i = 0, count = Mbuttonswrapper.getchildcount (); I < count; i++) {if (Mbuttonswrapper.getchildat (i) instanceof Inoutimagebutton) {View view = Mbuttonswrapper.getchildat (i); if ( View.getid () = = Subject.getid ()) {//Click the button to enlarge and disappear clickanimationset Clickset = new Clickanimationset (600); Clickset.setanimationlistener (New Customanimationlistener (view)); View.startanimation (Clickset);} else {//Not clicked button shrinks and disappears view.startanimation (new Notclickanimationset (600));}}} /** * button click Listener */private class Customanimationlistener implements Animationlistener {private View view;public Customanimat Ionlistener (view view) {This.view = view;} @Overridepublic void Onanimationstart (Animation Animation) {} @Overridepublic void Onanimationend (Animation Animation) {int id = view.getid (); switch (ID) {case r.id.button_weixinfriends://shared to Toast.maketext (Getapplicationcontext (), " Share to the circle of Friends ", Toast.length_short). Show (); Break;case r.id.button_friendsquan://share to Friends Circle Toast.maketext ( Getapplicationcontext (), "Share to Friends", Toast.length_short). Show (); Break;case R.id.button_clear:toast.maketext (Getapplicationcontext (), "clear track", Toast.length_short). Show (); break; Case R.id.button_reset:toast.maketext (Getapplicationcontext (), "Reset track", Toast.length_short). Show (); break;case R.id.button_screenshot:toast.maketext (Getapplicationcontext (), "screenshot", Toast.length_short). Show (); Break;default: Break;}} @Overridepublic void Onanimationrepeat (Animation Animation) {}}}

The button pops into the Popup tool class Animationcontrolutils:

Package Com.anim;import Android.view.viewgroup;import Android.view.animation.alphaanimation;import Android.view.animation.anticipateinterpolator;import Android.view.animation.overshootinterpolator;import Com.anim.abstractinoutanimationset.direction;import com.customview.inoutimagebutton;/** * button pops into Popup tool class * @author Zhongyao */public class Animationcontrolutils {//Animation total time unit milliseconds private static final int DIRECTION = 500;public static void sta Rtanimations (viewgroup buttons, Direction directioin,int Flagbutton) {switch (directioin) {case In:startanimationsin ( buttons, Flagbutton); Break;case out:startanimationsout (buttons, flagbutton); break;}} /** * @param buttons * All popup retract button collection */private static void Startanimationsin (viewgroup buttons, int flagbutton) {f inal int count = Buttons.getchildcount (); for (int i = 0; i < count; i++) {if (Buttons.getchildat (i) instanceof Inoutima Gebutton) {//For each pushbutton inoutimagebutton button = (Inoutimagebutton) buttons.getchildat (i); if (Flagbutton = = 4) {//button move animation POPupbuttonanimationset animation = new Popupbuttonanimationset (direction.in, Direction, button), long offset = i * +/(CO UNT-1)///Set Start animation time, the purpose is not to move the animation.setstartoffset (offset);//Set the rebound (overshoot) effect of the picture Animation.setinterpolator (new Overshootinterpolator (2.0f)); button.startanimation (animation);} Else{alphaanimation Myanimation_alpha = new Alphaanimation (0.0f,1.0f); Myanimation_alpha.setinterpolator (new Anticipateinterpolator (2.0F)); Myanimation_alpha.setfillafter (true); Button.startanimation (Myanimation_alpha);}}} /** * @param composerbuttons */private static void Startanimationsout (viewgroup buttons, int flagbutton) {Final int count = Buttons.getchildcount (); for (int i = 0; i < count; i++) {if ((Buttons.getchildat (i) instanceof Inoutimagebutton)} {in Outimagebutton button = (Inoutimagebutton) buttons.getchildat (i); if (Flagbutton = = 4) {Popupbuttonanimationset Animation = new Popupbuttonanimationset (direction.out, Direction, button); Long offset = (Count-1-i) * +/(count-1 );Animation.setstartoffset (offset); Animation.setinterpolator (new Anticipateinterpolator (2.0F)); Button.startanimation (animation);} else {alphaanimation Myanimation_alpha = new Alphaanimation (1.0f,0.0f); Myanimation_alpha.setinterpolator (new Anticipateinterpolator (2.0F)); Myanimation_alpha.setfillafter (false); button.startanimation (Myanimation_alpha);}}}}

Button animation abstract class Abstractinoutanimationset,anim the other three remaining classes in the package are integrated with the abstract class:

Package Com.anim;import android.view.view;import android.view.animation.animationset;/** * Button Animation abstract class * @author Zhongyao * /public abstract class Abstractinoutanimationset extends Animationset {/** * record current animation direction */private final Direction Mdirectioi N;public enum Direction {in, Out}public abstractinoutanimationset (Direction directioin, long duration,view[] views) { Super (TRUE); Mdirectioin = Directioin;switch (directioin) {case in:addinanimation, break;case out: Addoutanimation (views); After adding the animation, set the total Execution time setduration (duration);} Public Direction getdirection () {return mdirectioin;} /** * @param views */protected abstract void Addinanimation (view[),/** * @param views */protected abstract void add Outanimation (view[] views);}

Popup Recall button Move track animation collection Popupbuttonanimationset:
Package Com.anim;import Android.view.view;import Android.view.viewgroup;import android.view.animation.translateanimation;/** * Popup recall button move Track Animation collection */public class Popupbuttonanimationset extends Abstractinoutanimationset {private static final int mxoffset = 16;private static final int myoffset = 243;public Popupbutt Onanimationset (Direction directioin, long Duration,view subject) {Super (Directioin, duration, new view[]{subject});  /** 480 * 800 Value change Law on mobile phone pops up x = 0.0, y = 456.0x = -62.0, y = 446.0x = -118.0, y = 418.0x = -162.0, y = 374.0x = -190.0, y = 318.0x = -200.0, y = 256.0*/@Overrideprotected void addinanimation (view[] views) {Viewgroup.marginlayoutparams LAYOUTP Arams = (viewgroup.marginlayoutparams) views[0].getlayoutparams ();//calculate the movement trajectory of each popup retract button float x =- Layoutparams.leftmargin + mxoffset;float y = layoutparams.bottommargin + myoffset;//Move position animation translateanimation Translateanimation = new Translateanimation (x, 0.0f, y, 0.0f); Addanimation (translateanimation);} /** retract x = 0.0, y = 456.0x =-62.0, y = 446.0x = -118.0, y = 418.0x = -162.0, y = 374.0x = -190.0, y = 318.0x = -200.0, y = 256.0 */@Overrideprote CTED void Addoutanimation (view[] views) {Viewgroup.marginlayoutparams Layoutparams = (viewgroup.marginlayoutparams) Views[0].getlayoutparams (); float x =-layoutparams.leftmargin + Mxoffset;float y = layoutparams.bottommargin + mYOffset; translateanimation animation = new Translateanimation (0.0F, X, 0.0F, y); addanimation (animation);}}

Click the button to enlarge and disappear the animation collection Clickanimationset:

Package Com.anim;import Android.view.view;import Android.view.animation.alphaanimation;import Android.view.animation.animation;import android.view.animation.scaleanimation;/** * Click the button to enlarge and disappear the animation collection */public class Clickanimationset extends Abstractinoutanimationset {public clickanimationset (long duration) {super (direction.out, Duration, null);} @Overrideprotected void Addinanimation (view[] views) {} @Overrideprotected void Addoutanimation (view[] views) { Addanimation (New Scaleanimation (1.0F, 5.0F, 1.0F, 5.0F, 1, 0.5f,animation.relative_to_self, 0.5F));    Addanimation (New Alphaanimation (1.0F, 0.0F));}}

Eject button click after animation notclickanimationset:

Package Com.anim;import Android.view.view;import Android.view.animation.alphaanimation;import Android.view.animation.animation;import android.view.animation.scaleanimation;/** * Eject button click after animation */public class Notclickanimationset extends Abstractinoutanimationset {public notclickanimationset (long duration) {// Just control directly call Addoutanimationsuper (direction.out, duration, null);} @Overrideprotected void Addinanimation (view[] views) {} @Overrideprotected void Addoutanimation (view[] views) { Addanimation (New Scaleanimation (1.0F, 0.0F, 1.0F, 0.0F, Animation.relative_to_self, 0.5F, 1, 0.5F)); Addanimation (new Alphaanimation (1.0F, 0.0F));}}

Here are the custom layouts, custom buttons that have been referenced in the layout:

Custom layout inoutrelativelayout:

Package Com.customview;import Android.content.context;import Android.util.attributeset;import Android.view.View; Import Android.view.animation.animation;import Android.view.animation.animationset;import Android.widget.relativelayout;import Com.anim.abstractinoutanimationset;import Com.anim.abstractinoutanimationset.direction;public class Inoutrelativelayout extends Relativelayout {private Animation Manimation;public inoutrelativelayout (context context) {super (context);} Public Inoutrelativelayout (context context, AttributeSet Attrs) {Super (context, attrs);} Public Inoutrelativelayout (context context, AttributeSet attrs, int defstyle) {Super (context, attrs, Defstyle);} @Overrideprotected void Onanimationstart () {Super.onanimationstart (); if (manimation instanceof Animationset) { Setvisibility (view.visible);}} @Overrideprotected void Onanimationend () {super.onanimationend (); if (manimation instanceof Abstractinoutanimationset ) {Abstractinoutanimationset Animationset = (abstractinoutanimationset) Manimation;if (animationset.getdirection () = = Direction.out) {setvisibility (view.gone);} else {setvisibility ( view.visible);}}} @Overridepublic void Startanimation (Animation Animation) {super.startanimation (Animation); manimation = Animation; Getrootview (). Postinvalidate ();}}

Eject, retract button Inoutimagebutton:

Package Com.customview;import Android.content.context;import Android.util.attributeset;import Android.view.View; Import Android.view.animation.animation;import Android.widget.imagebutton;import com.anim.abstractinoutanimationset;/** * Eject, retract button */public class Inoutimagebutton extends ImageButton {private Animation Manimation;public Inoutimagebutton (Context context) {super (context);} Public Inoutimagebutton (context context, AttributeSet Attrs) {Super (context, attrs);} Public Inoutimagebutton (context context, AttributeSet attrs, int defstyle) {Super (context, attrs, Defstyle);} @Overrideprotected void Onanimationstart () {Super.onanimationstart (); if (Manimation instanceof Abstractinoutanimationset) {setvisibility (view.visible);}} @Overrideprotected void Onanimationend () {super.onanimationend (); if (manimation instanceof Abstractinoutanimationset ) {Abstractinoutanimationset animation = (abstractinoutanimationset) manimation;if (animation.getdirection () = = Com.anim.AbstractInOutAnimationSet.Direction. Out) {setvisibility (view.gone);} else {setvisibility (view.visible);}}} @Overridepublic void Startanimation (Animation Animation) {super.startanimation (Animation); manimation = Animation; Getrootview (). Postinvalidate ();}}

Basic is these, below I provide the next source, we can combine the following source to see:

Click to download the source code



Android's Custom multiple button view similar to Arcmenu (open source project on GitHub)

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.