Android (6) Sector menu implementation

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size:24px"><strong>A. fan-shaped menu Implementation:</strong></span></p></p><p><p><span style="font-size:24px"><strong></strong></span> <span style="font-size:18px">Drawing on the source of the great gods, let's look at how the sector menu is implemented:</span></p></p><p><p><span style="font-size:18px">:</span></p></p><p><p><span style="font-size:24px"><strong></strong></span></p></p><p><p><span style="font-size:24px"><strong></strong></span></p></p><p><p><span style="font-size:24px"><strong><br></strong></span></p></p><p><p></p></p><p><p><br></p></p><p><p><span style="font-size:18px">Main interface Layout:</span></p></p><p><p><span style="font-size:18px"></span></p></p><pre code_snippet_id="673871" snippet_file_name="blog_20150524_1_9571635" class="html" name="code"><relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "fill_parent" android:layout_height= "fill_parent" android:background= "@drawable/background" > <!--android:clipchild Ren's Meaning: Does it limit the Sub-view within its scope android:cliptopadding that the drawing area of the control is inside Padding--<relativelayout android:id= " @+id/buttons_wrapper_layout "android:layout_width=" fill_parent "android:layout_height=" fill_parent "a ndroid:layout_alignparentbottom= "true" android:layout_alignparentright= "true" android:clipchildren= "false" android:cliptopadding= "false" > <imagebutton android:id= "@+id/button_photo" andro Id:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_alignparentbottom = "true" android:layout_alignparentright= "true" android:layout_marginbottom= "142dp" Androi d:layout_marginright= "10dp" android:background= "@drawable/path2_composer_camera" android:visibility= "gone"/> <ima Gebutton android:id= "@+id/button_people" android:layout_width= "wrap_content" Android:layo ut_height= "wrap_content" android:layout_alignparentbottom= "true" android:layout_alignparentright= "tr UE "android:layout_marginbottom=" 135DP "android:layout_marginright=" 52DP "android:backgro und= "@drawable/path2_composer_with" android:visibility= "gone"/> <imagebutton android:i d= "@+id/button_place" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_alignparentbottom= "true" android:layout_alignparentright= "true" android:layout_ marginbottom= "116dp" android:layout_marginright= "89dp" android:background= "@drawable/path2_composer_ Place "android:visibility= "gone"/> <imagebutton android:id= "@+id/button_music" android:layout_width = "wrap_content" android:layout_height= "wrap_content" android:layout_alignparentbottom= "true" android:layout_alignparentright= "true" android:layout_marginbottom= "87dp" android:layout_marginr ight= "118dp" android:background= "@drawable/path2_composer_music" android:visibility= "gone"/> <imagebutton android:id= "@+id/button_thought" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_alignparentbottom= "true" android:layout_alignpar entright= "true" android:layout_marginbottom= "50dp" android:layout_marginright= "137dp" and roid:background= "@drawable/path2_composer_thought" android:visibility= "gone"/> <imagebutton Android:id= "@+id/bUtton_sleep "android:layout_width=" wrap_content "android:layout_height=" wrap_content "and roid:layout_alignparentbottom= "true" android:layout_alignparentright= "true" Android:layout_marginbot tom= "8dp" android:layout_marginright= "144dp" android:background= "@drawable/path2_composer_sleep" android:visibility= "gone"/> </RelativeLayout> <relativelayout android:id= "@+id/buttons_s How_hide_button_layout "android:layout_width=" 60dp "android:layout_height=" 57DP "android:layout_align parentbottom= "true" android:layout_alignparentright= "true" android:background= "@drawable/path2_composer_butt On "> <imageview android:id=" @+id/buttons_show_hide_button "android:layout_width=" wrap_ Content "android:layout_height=" Wrap_content "android:layout_centerinparent=" true "androi D:src= "@drawable/path2_cOmposer_icn_plus "/> </RelativeLayout></RelativeLayout> </pre><br>Activity:<p><p></p></p><p><p><span style="font-size:18px"></span></p></p><pre code_snippet_id="673871" snippet_file_name="blog_20150524_2_1703134" class="java" name="code">public class Mainactivity extends Activity {private boolean isshowing;private relativelayout buttons_wrapper_layout; Private ImageView buttons_show_hide_button;private Relativelayout buttons_show_hide_button_layout; @Override protected void onCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.sector_menu); Myanimations.initoffset (mainactivity.this); buttons_wrapper_layout = (relativelayout) findViewById (R.id.buttons_ wrapper_layout); buttons_show_hide_button_layout = (relativelayout) Findviewbyid (r.id.buttons_show_hide_button_ layout); Buttons_show_hide_button = (ImageView) Findviewbyid (r.id.buttons_show_hide_button); buttons_show_hide_ Button_layout.setonclicklistener (new onclicklistener () {@Overridepublic void OnClick (View v) {if (!isshowing) { Myanimations.startanimationsin (buttons_wrapper_layout), Buttons_show_hide_button.startanimation ( Myanimations.getrotateanimation (0,-270, 300));} else {myanimations.startanimatioNsout (buttons_wrapper_layout), buttons_show_hide_button.startanimation (myanimations.getrotateanimation (-270 , 0, 300));} Isshowing =!isshowing;}}); for (int i = 0; i < buttons_wrapper_layout.getchildcount (); I++) {buttons_wrapper_layout.getchildat (i). Setonclicklistener (new Onclickimagebutton ());} } class Onclickimagebutton implements View.onclicklistener{@Overridepublic void OnClick (View arg0) {switch (arg 0.getId ()) {case r.id.button_photo:toast.maketext (mainactivity.this, "photo", toast.length_short). show (); Case R.id.button_people:toast.maketext (mainactivity.this, "people", toast.length_short). show (); break;case R.id.button_place:toast.maketext (mainactivity.this, "place", toast.length_short). show (); break;case R.id.button_ Music:Toast.makeText (mainactivity.this, "music", toast.length_short). show (); break;case r.id.button_thought: Toast.maketext (mainactivity.this, "thought", toast.length_short). show (); break;case r.id.button_sleep: Toast.maketext (mainactivity.this, "SLEep ", toast.length_short). Show (); break;}} }}</pre><br><br><p><p></p></p><p><p><span style="font-size:18px">Animation implementation:</span></p></p><p><p><span style="font-size:18px"></span></p></p><pre code_snippet_id="673871" snippet_file_name="blog_20150524_3_7639268" class="java" name="code">public class myanimations {private static int xoffset = 15;private static int yoffset = -13;public static void Initoffset ( Context Context) {//gets The screen density context.getresources (). getdisplaymetrics (). density set the distance to move Xoffset = (int) (10 * Context.getresources (). getdisplaymetrics (). density); yoffset =-(int) (8 * context.getresources (). getdisplaymetrics ( ). density);} public static Animation getrotateanimation (float fromdegrees,float todegrees, int durationmillis) {//rotation, first two parameters set rotation angle, After four set the rotation center rotateanimation rotate = new Rotateanimation (fromdegrees, todegrees,animation.relative_to_self, 0.5f, Animation.relative_to_self,0.5f)///duration Rotate.setduration (durationmillis);//after The end of the animation, stay in the last second rotate.setfillafter ( true); return rotate;} public static void Startanimationsin (viewgroup viewgroup, int. Durationmillis) {for (int i = 0; i < Viewgroup.getchildco UNT (); I++) {ImageButton Inoutimagebutton = (ImageButton) viewgroup.getchildat (i);//display picture inoutimagebutton.setvisibility ( view.visible); Marginlayoutparams MLP = (MargiNlayoutparams) inoutimagebutton.getlayoutparams ();//displacement Distance Animation animation = new Translateanimation ( mlp.rightmargin-xoffset, 0F, Yoffset + mlp.bottommargin, 0F); After the animation ends, stay at the last frame animation.setfillafter (true);//animation duration animation.setduration (durationmillis);// Start Time animation.setstartoffset ((i * +)/( -1 + viewgroup.getchildcount ())); animation.setinterpolator (new Overshootinterpolator (2F));//add Animation Inoutimagebutton.startanimation (animation);}} public static void Startanimationsout (viewgroup viewgroup,int durationmillis) {for (int i = 0; i < Viewgroup.getchildco UNT (); I++) {final ImageButton Inoutimagebutton = (ImageButton) Viewgroup.getchildat (i); Marginlayoutparams MLP = (marginlayoutparams) inoutimagebutton.getlayoutparams (); Animation Animation = new translateanimation (0F, mlp.rightmargin-xoffset, 0F, yoffset + mlp.bottommargin); Animation.setfillafter (true); animation.setduration (durationmillis); animation.setstartoffset (( Viewgroup.getchildcount ()-i) * ( -1 + vie)Wgroup.getchildcount ())); animation.setinterpolator (new anticipateinterpolator (2F));// Set the animation listener Animation.setanimationlistener (new animation.animationlistener () {@Overridepublic void Onanimationstart ( Animation arg0) {} @Overridepublic void onanimationrepeat (Animation arg0) {}//after The end of the animation, hide Imagebutton@overridep ublic void Onanimationend (Animation arg0) {inoutimagebutton.setvisibility (view.gone);}}); Inoutimagebutton.startanimation (animation);}}}</pre><br>That's the whole Realization.<p><p></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p><br></p></p><p><p>Android (6) Sector menu implementation</p></p></span>

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.