Found 2 versions of android-support-v4.jar in the dependency list, but not all the versions are identical (check is based on SHA-1 only at this time). All versions of the libraries must be the same at this time. Versions found are: Path: /Users/baozi/Documents/Dev/HuihuaWorkspace/actionbarsherlock/libs/android-support-v4.jar Length: 271754 SHA-1: 53307dc2bd2b69fd5533458ee11885f55807de4b Path: /Users/baozi/Documents/Dev/HuihuaWorkspace/library/libs/android-support-v4.jar Length: 758727 SHA-1: efec67655f6db90757faa37201efcee2a9ec3507 Jar mismatch! Fix your dependencies
public class SlidingFragmentActivity extends FragmentActivity
public class SlidingFragmentActivity extends SherlockFragmentActivity
public class SlidingExample extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(R.string.attach); // set the content view setContentView(R.layout.content); // configure the SlidingMenu SlidingMenu menu = new SlidingMenu(this); menu.setMode(SlidingMenu.LEFT); menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); menu.setShadowWidthRes(R.dimen.shadow_width); menu.setShadowDrawable(R.drawable.shadow); menu.setBehindOffsetRes(R.dimen.slidingmenu_offset); menu.setFadeDegree(0.35f); menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); menu.setMenu(R.layout.menu); } }
SlidingMenu menu = getSlidingMenu();
menu.setBehindOffset(getWindowManager().getDefaultDisplay().getWidth() / 5);
// getWindowManager().getDefaultDisplay().getWidth() / 5 表示 距离屏幕宽度 1/5
sm = getSlidingMenu(); setBehindContentView(R.layout.main_menu_frame); sm.setSecondaryMenu(R.layout.main_menu_frame_two); messageFragment = new MessageFragment(); profileFragment = new ProfileFragment(); getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame, messageFragment).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame_two, profileFragment).commit();
设置布局有3个方法 :
setContentView(R.layout.main); //设置slidingmenu中间的布局
setBehindContentView(R.layout.main_menu_frame);//设置左侧的布局
sm.setSecondaryMenu(R.layout.main_menu_frame_two);//设置右侧的布局
使用的是左右两侧 我一般设置为 fragment
getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame,messageFragment).commit();
表示为替换 fragmentmenu.setTouchModeBehind(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);监听主要分2种 open 和 close
open:
menu.setOnOpenedListener(onOpenListener);//监听slidingmenu打开之后调用
menu.setOnOpenListener(onOpenListener);//监听slidingmenu打开时调用
close:
两个监听器 注意看了 一个是 closed 一个是 close
menu.setOnClosedListener(listener);
menu.setOnCloseListener(listener);
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17" />
//┏┓ ┏┓ //┏┛┻━━━┛┻┓ //┃ ┃ //┃ ━ ┃ //┃ ┳┛ ┗┳ ┃ //┃ ┃ //┃ ┻ ┃ //┃ ┃ //┗━┓ ┏━┛ // ┃ ┃ 神兽保佑 // ┃ ┃ 代码无BUG! // ┃ ┗━━━┓ // ┃ ┣┓ // ┃ ┏┛ // ┗┓┓┏━┳┓┏┛ // ┃┫┫ ┃┫┫ // ┗┻┛ ┗┻┛