The example of this article for you to share the Android classification of Sideslip menu production methods for your reference, the specific content as follows
Classificmenuactivity.java Code:
Package Com.siso.crazyworld;
Import Android.animation.Animator;
Import android.content.res.Configuration;
Import Android.graphics.Color;
Import android.graphics.drawable.BitmapDrawable;
Import Android.os.Bundle;
Import Android.support.v4.widget.DrawerLayout;
Import android.support.v7.app.ActionBarActivity;
Import Android.support.v7.app.ActionBarDrawerToggle;
Import Android.support.v7.widget.Toolbar;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.view.View;
Import Android.view.ViewAnimationUtils;
Import Android.view.animation.AccelerateInterpolator;
Import Android.widget.LinearLayout;
Import com.siso.crazyworld.fragment.ContentFragment;
Import java.util.ArrayList;
Import java.util.List;
Import sidemenu.interfaces.Resourceble;
Import sidemenu.interfaces.ScreenShotable;
Import Sidemenu.model.SlideMenuItem;
Import Sidemenu.util.ViewAnimator; public class Classificmenuactivity extends Actionbaractivity implements Viewanimator.viewanimatorlistener {private DrawErlayout drawerlayout;
Private Actionbardrawertoggle Drawertoggle;
Private list<slidemenuitem> List = new arraylist<> ();
Private Contentfragment contentfragment;
Private Viewanimator Viewanimator;
private int res = R.drawable.content_music;
Private LinearLayout LinearLayout;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_classificmenu);
Contentfragment = Contentfragment.newinstance (R.drawable.content_music);
Getsupportfragmentmanager (). BeginTransaction (). replace (R.id.content_frame, contentfragment). commit ();
Drawerlayout = (drawerlayout) Findviewbyid (r.id.drawer_layout);
Drawerlayout.setscrimcolor (color.transparent);
LinearLayout = (linearlayout) Findviewbyid (r.id.left_drawer); Linearlayout.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) {drawerlayou
T.closedrawers ();
}
});
Setactionbar (); CreatemeNulist ();
Viewanimator = new Viewanimator<> (this, list, contentfragment, drawerlayout, this); private void Createmenulist () {Slidemenuitem menuItem0 = new Slidemenuitem (Contentfragment.close, R.DRAWABLE.ICN_CL
OSE);
List.add (MENUITEM0);
Slidemenuitem MenuItem = new Slidemenuitem (contentfragment.building, r.drawable.icn_1);
List.add (MenuItem);
Slidemenuitem menuItem2 = new Slidemenuitem (Contentfragment.book, r.drawable.icn_2);
List.add (MENUITEM2);
Slidemenuitem menuItem3 = new Slidemenuitem (Contentfragment.paint, r.drawable.icn_3);
List.add (MENUITEM3);
Slidemenuitem menuItem4 = new Slidemenuitem (contentfragment.case, r.drawable.icn_4);
List.add (MENUITEM4);
Slidemenuitem MENUITEM5 = new Slidemenuitem (Contentfragment.shop, r.drawable.icn_5);
List.add (MENUITEM5);
Slidemenuitem menuItem6 = new Slidemenuitem (Contentfragment.party, r.drawable.icn_6);
List.add (MENUITEM6); Slidemenuitem MenuItem7 = new Slidemenuitem (Contentfragment.movie, R.drawable.icN_7);
List.add (MENUITEM7);
private void Setactionbar () {Toolbar Toolbar = (Toolbar) Findviewbyid (R.id.toolbar);
Setsupportactionbar (toolbar);
Getsupportactionbar (). Sethomebuttonenabled (True);
Getsupportactionbar (). Setdisplayhomeasupenabled (True);
Drawertoggle = new Actionbardrawertoggle (this,/* host activity/drawerlayout,/* Drawerlayout Object * * toolbar,/* NAV drawer icon to replace the ' up ' caret * * r.string.drawer_open,/* "Open drawer" description * * R.S Tring.drawer_close/* "Close drawer" description/) {/** Called when a drawer has settled in a completely closed State.
*/public void ondrawerclosed (view view) {super.ondrawerclosed (view);
Linearlayout.removeallviews ();
Linearlayout.invalidate (); @Override public void Ondrawerslide (View drawerview, float slideoffset) {super.ondrawerslide (Drawerview, SLI
Deoffset); if (Slideoffset > 0.6 && linearlayout.getchildcount () = = 0) VIEwanimator.showmenucontent (); /** called when a drawer has settled to a completely open state.
*/public void ondraweropened (View drawerview) {super.ondraweropened (Drawerview);
}
};
Drawerlayout.setdrawerlistener (Drawertoggle);
} @Override protected void Onpostcreate (Bundle savedinstancestate) {super.onpostcreate (savedinstancestate);
Drawertoggle.syncstate ();
@Override public void onconfigurationchanged (Configuration newconfig) {super.onconfigurationchanged (newconfig);
Drawertoggle.onconfigurationchanged (Newconfig);
@Override public boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.menu_main, menu);
return true;
@Override public boolean onoptionsitemselected (MenuItem item) {if (drawertoggle.onoptionsitemselected (item)) {
return true;
Switch (Item.getitemid ()) {case R.id.action_settings:return true;
Default:return super.onoptionsitemselected (item); }} Private screenshotAble Replacefragment (screenshotable screenshotable, int topposition) {This.res = This.res = = R.drawable.content_music?
R.drawable.content_films:r.drawable.content_music;
View view = Findviewbyid (R.id.content_frame);
int Finalradius = Math.max (View.getwidth (), View.getheight ());
Animator Animator = viewanimationutils.createcircularreveal (view, 0, topposition, 0, Finalradius);
Animator.setinterpolator (New Accelerateinterpolator ());
Animator.setduration (viewanimator.circular_reveal_animation_duration); Findviewbyid (R.id.content_overlay). SetBackground (New Bitmapdrawable (Getresources (), Screenshotable.getbitmap ())
;
Animator.start ();
Contentfragment contentfragment = contentfragment.newinstance (this.res);
Getsupportfragmentmanager (). BeginTransaction (). replace (R.id.content_frame, contentfragment). commit ();
return contentfragment;
@Override public screenshotable Onswitch (resourceble slidemenuitem, screenshotable screenshotable, int position) { Switch (slidemEnuitem.getname ()) {case ContentFragment.CLOSE:return screenshotable;
Default:return replacefragment (screenshotable, position);
@Override public void Disablehomebutton () {Getsupportactionbar (). sethomebuttonenabled (false);
@Override public void Enablehomebutton () {Getsupportactionbar (). Sethomebuttonenabled (True);
Drawerlayout.closedrawers ();
@Override public void Addviewtocontainer (view view) {Linearlayout.addview;
}
}
Contentfragment.java code under Fragment folder:
Package com.siso.crazyworld.fragment;
Import Android.graphics.Bitmap;
Import Android.graphics.Canvas;
Import Android.os.Bundle;
Import android.support.annotation.Nullable;
Import android.support.v4.app.Fragment;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.ImageView;
Import COM.SISO.CRAZYWORLD.R;
Import sidemenu.interfaces.ScreenShotable;
public class Contentfragment extends Fragment implements screenshotable {public static final String close = ' close ';
public static final String building = "building";
public static final String book = "book";
public static final String PAINT = "PAINT";
Public-static final String case = ' case ';
public static final String shop = "Shop";
public static final String party = "Party";
public static final String MOVIE = "MOVIE";
Private View Containerview;
protected ImageView Mimageview;
protected int res;
Private Bitmap Bitmap; public static Contentfragment NewinstancE (int resid) {contentfragment contentfragment = new Contentfragment ();
Bundle Bundle = new Bundle ();
Bundle.putint (Integer.class.getName (), resid);
Contentfragment.setarguments (bundle);
return contentfragment; @Override public void onviewcreated (view view, @Nullable Bundle savedinstancestate) {super.onviewcreated view, SA
Vedinstancestate);
This.containerview = View.findviewbyid (R.id.container);
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
res = Getarguments (). GetInt (Integer.class.getName ());
@Override public View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {
View Rootview = inflater.inflate (R.layout.fragment_main, container, false);
Mimageview = (ImageView) Rootview.findviewbyid (r.id.image_content);
Mimageview.setclickable (TRUE);
Mimageview.setfocusable (TRUE);
Mimageview.setimageresource (RES);
return rootview; } @Override Public VoiD takescreenshot () {Thread thread = new Thread () {@Override public void run () {Bitmap Bitmap = bitmap.creat
Ebitmap (Containerview.getwidth (), Containerview.getheight (), Bitmap.Config.ARGB_8888);
Canvas Canvas = new Canvas (bitmap);
Containerview.draw (canvas);
ContentFragment.this.bitmap = bitmap;
}
};
Thread.Start ();
@Override public Bitmap Getbitmap () {return Bitmap;
}
}
Activity_classificmenu.xml content:
<android.support.v4.widget.drawerlayout xmlns:android= "Http://schemas.android.com/apk/res/android" Android:id = "@+id/drawer_layout" android:layout_width= "match_parent" android:layout_height= "Match_parent" > < Io.codetail.widget.RevealFrameLayout android:id= "@+id/container_frame" xmlns:android= "http://schemas.android.com
/apk/res/android "android:layout_width=" match_parent "android:layout_height=" match_parent "> <LinearLayout Android:id= "@+id/content_overlay" android:layout_width= "match_parent" android:layout_height= "Match_parent" Androi d:orientation= "vertical"/> <linearlayout android:id= "@+id/content_frame" android:layout_width=
"Android:layout_height=" match_parent "android:orientation=" vertical "/> <android.support.v7.widget.toolbar Android:id= "@+id/toolbar" android:layout_height= "wrap_content" android:layout_width= "Match_parent" android:min height= "Attr/actionbarsize" android:background= "?? attr/colorprimary "/> </io.codetail.widget.RevealFrameLayout> <scrollview android:id=" @+id/scrollview
"Android:scrollbarthumbvertical=" @android: Color/transparent "android:layout_width=" @dimen/sliding_menu_width " android:layout_height= "Match_parent" android:layout_gravity= "Start|bottom" > <linearlayout android:id= "@+id/" Left_drawer "android:orientation=" vertical "android:layout_width=" @dimen/sliding_menu_width "Android:layout_heigh t= "Wrap_content" android:divider= "@android: Color/transparent" android:background= "@android: Color/transparent"
> </LinearLayout> </ScrollView> </android.support.v4.widget.DrawerLayout>
. XML content:
<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
<item android:state_pressed=" true "android:drawable=" @drawable/item_down "/>
<item Android:state_selected= "true" android:drawable= "@drawable/item_down"/>
<item android:state_focused= " True "android:drawable=" @drawable/item_down/>
<item android:drawable= "@drawable/item_up"/>
</selector>
Fragment_main.xml content:
<?xml version= "1.0" encoding= "Utf-8"?> <io.codetail.widget.revealframelayout xmlns:android=
" Http://schemas.android.com/apk/res/android "
android:layout_width=" match_parent "
android:layout_height= "Match_parent" >
<framelayout
android:id= "@+id/container"
android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >
<imageview
android:scaletype= "Fitxy"
android:id = "@+id/image_content"
android:src= "@drawable/content_films"
android:layout_width= "Match_parent"
android:layout_height= "match_parent"/>
</FrameLayout>
</ Io.codetail.widget.revealframelayout>
Strings.xml:
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string name= "App_name" >crazyworld </string>
<string name= "action_settings" > Settings </string>
<string name= "Drawer_open" > open</string>
<string name= "Drawer_close" >Close</string>
</resources>
Styles.xml
<resources>
<!--Base application theme.-->
<style name= "Apptheme" parent= " Theme.AppCompat.Light.NoActionBar ">
</style>
</resources>
Run Result:
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.