*** Please reprint statement Source: ***
/**
SlidingMenu download: visit https://github.com/Trinea/android-open-project site, and then search SlidingMenu.
First to speak SlidingMenu added to your project created by p'ropreies in the add.
*/
menu.setMode (SlidingMenu.LEFT); // Set the left sliding menu
menu.setTouchModeAbove (SlidingMenu.TOUCHMODE_FULLSCREEN); // set the sliding screen limitation, the full-screen area can be set to slide
menu.setShadowDrawable (R.drawable.shadow); // set Shadow
menu.setShadowWidthRes (R.dimen.shadow_width); // set the width of the shadow
menu.setBehindOffsetRes (R.dimen.slidingmenu_offset); // SlidingMenu residual draw when the remaining surface of the display width of the page
menu.setBehindWidth (400); // set the width of the menu SlidingMenu
menu.setFadeDegree (0.35f); // SlidingMenu degree of sliding when the gradient
menu.attachToActivity (this, SlidingMenu.SLIDING_CONTENT); // make SlidingMenu attached on Activity
menu.setMenu (R.layout.menu_layout); // set menu layout file
menu.toggle (); // dynamic initiative to conclude a closed or open SlidingMenu
menu.showMenu (); // 显示 SlidingMenu
menu.showContent (); // display content
menu.setOnOpenListener(onOpenListener);//slidingmenu打开
About two enclosed menu, simple, for the menu close transactions, one when, one after
menu.OnClosedListener (OnClosedListener); // slidingmenu when the transaction is closed
menu.OnClosedListener (OnClosedListener); // slidingmenu after the transaction is closed
It can only be set aside SlidingMenu menu
menu.setMode (SlidingMenu.LEFT_RIGHT); attribute, then set the right of the menu layout file
menu.setSecondaryShadowDrawable (R.drawable.shadowright); // menu on the right shadow
Application Fragment achieve SlidingMenu:
1. First Activity sustained self SlidingMenu the packet SlidingFragmentActivity
2. the setContentView (R.layout.content_frame); // the layout of a full screen of the FrameLayout
3. setBehindContentView (R.layout.menu_frame); // set the layout application SlidingMenu , also a full-screen the FrameLayout
4. Fragment left menu provided SlidingMenu
setBehindContentView(R.layout.menu_frame);
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
leftMenuFragment = new MenuFragment();
t.replace(R.id.menu_frame, leftMenuFragment);
t.commit();
MenuFragment is actually a Fragment, display a ListView
and then click the ListView every hour, informing Activity switches incompatible Fragment
To see the results, we create five Frament, are
Fragment1, Fragment2, Fragment3, Fragment4, Fragment5
in SlidingMenu top display ListView.
Set Fragment main page is displayed:
if (savedInstanceState == null) {//== null的时辰新建Fragment1
contentFragment = new Fragment1();
} else {//不便是null,直接get出来
//不便是null,找出之前保存的当前Activity显示的Fragment
contentFragment = getSupportFragmentManager().getFragment(savedInstanceState, "contentFragment");
}
//设置内容Fragment
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, contentFragment)
.commit();
Save the currently displayed in the Activity onSaveInstanceState Fragment
getSupportFragmentManager () putFragment (outState, "contentFragment", contentFragment);.
Setting property SlidingMenu
SM = getSlidingMenu ();
// if only the menu is displayed on the left side with the LEFT, RIGHT on the right , you have to support LEFT_RIGHT
sm.setMode (SlidingMenu.LEFT_RIGHT); // sliding mode setting menu, the menu is in the form now left or right, or on both sides you
sm.setShadowDrawable (R.drawable.shadow); / / shadow set data
sm.setShadowWidthRes (R.dimen.shadow_width); // set the width of the shadow
//sm.setBehindWidth(200);// width setting menu
sm.setBehindOffsetRes (R.dimen.slidingmenu_offset); // when SlidingMenu draw page shows the width of the scraps
sm.setTouchModeAbove (SlidingMenu.TOUCHMODE_FULLSCREEN); // set slides in
Support the right of draw menu:
// SlidingMenu can simultaneously support both sides of the draw menu Excellency, do not conflict, and beautifully animated and experience outstanding.
sm.setSecondaryMenu (R.layout.menu_frame2); // set the right side of the menu
sm.setSecondaryShadowDrawable (R.drawable.shadowright); // set the data to the right of the menu Shadow
// SlidingMenu right side of Fragment
. getSupportFragmentManager () beginTransaction ( .) .replace (R.id.menu_frame2, new SampleListFragment ()) commit ();
Settings can be clicked ActionBar:
getSupportActionBar () setHomeButtonEnabled (to true); // ActionBar master keys is clicked.
GetSupportActionBar () setDisplayHomeAsUpEnabled (to true); // display the icon to the left.
SetSlidingActionBarEnabled (to false); // you both slidingmenu the fragment whether to display the title bar
Switching the page shows Fragment:
public void switchContent (Fragment F) {
// Fragment assigned to the content, and stored at this onSaveInstanceState Fragment
contentFragment = F;
FragmentTransaction getSupportFragmentManager = T () beginTransaction ();.
T.replace (R & lt. id.content_frame, F);
t.commit ();
sm.showContent ();
application popular Activity achieved SlidingMenu:
slidingMenu menu = new SlidingMenu(this);//直接new,而不是getSlidingMenu
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowDrawable(R.drawable.shadow);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setBehindWidth(400);//设置SlidingMenu菜单的宽度
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);//必须调用
menu.setMenu(R.layout.menu_layout_left);//就是通俗的layout布局
menu.setBehindCanvasTransformer(mTransformer);
Click in response SlidingMenu affairs, because SlidingMenu has been included in the Activity in, so direct findViewById (id), then get the view you can deal with the response.
You can support both sides of the draw menu
menu.setSecondaryMenu (R.layout.menu_layout_right);
menu.setSecondaryShadowDrawable (R.drawable.shadowright);
right-hand menu as direct findViewById (id), then it can easily get a view whims deal with the
Exchange SlidingMenu animation
Defined incompatible animation left slider or right slider SlidingMenu support, comprising drawing, scaling, twisting and other animation. It is in the process of sliding, how SlidingMenu rendered animation.
Animation applications are very simple
chapeau defined CanvasTransformer mTransformer; variables:
mTransformer = new CanvasTransformer() {
@Override
public void transformCanvas(Canvas canvas, float percentOpen) {
float scale = (float) (percentOpen*0.25 + 0.75);
canvas.scale(scale, scale, canvas.getWidth()/2, canvas.getHeight()/2);
}
};
Then mTransformer object was set SlidingMenu can be, this is the zoom animation:
void initSlidUpCanvasTransformer() {
mTransformer = new CanvasTransformer() {
@Override
public void transformCanvas(Canvas canvas, float percentOpen) {
canvas.translate(0, canvas.getHeight()*(1-interp.getInterpolation(percentOpen)));
}
};
}
private static Interpolator interp = new Interpolator() {
@Override
public float getInterpolation(float t) {
t -= 1.0f;
return t * t * t + 1.0f;
}
};
Tensile Animation:
mTransformer = new CanvasTransformer() {
@Override
public void transformCanvas(Canvas canvas, float percentOpen) {
canvas.scale(percentOpen, 1, 0, 0);
}
});