2013.12.04 (3)——— android SlidingMenu之PropertiesActivity
package com.jeremyfeinstein.slidingmenu.example;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.RadioGroup;import android.widget.RadioGroup.OnCheckedChangeListener;import android.widget.SeekBar;import android.widget.SeekBar.OnSeekBarChangeListener;import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;public class PropertiesActivity extends BaseActivity { public PropertiesActivity() { super(R.string.properties); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setSlidingActionBarEnabled(true); setContentView(R.layout.properties); // left and right modes RadioGroup mode = (RadioGroup) findViewById(R.id.mode); mode.check(R.id.left); mode.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { SlidingMenu sm = getSlidingMenu(); switch (checkedId) { case R.id.left: sm.setMode(SlidingMenu.LEFT); sm.setShadowDrawable(R.drawable.shadow); break; case R.id.right: sm.setMode(SlidingMenu.RIGHT); sm.setShadowDrawable(R.drawable.shadowright); break; case R.id.left_right: sm.setMode(SlidingMenu.LEFT_RIGHT); sm.setSecondaryMenu(R.layout.menu_frame_two); getSupportFragmentManager() .beginTransaction() .replace(R.id.menu_frame_two, new SampleListFragment()) .commit(); sm.setSecondaryShadowDrawable(R.drawable.shadowright); sm.setShadowDrawable(R.drawable.shadow); } } }); // touch mode stuff RadioGroup touchAbove = (RadioGroup) findViewById(R.id.touch_above); touchAbove.check(R.id.touch_above_full); touchAbove.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.touch_above_full: getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); break; case R.id.touch_above_margin: getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); break; case R.id.touch_above_none: getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE); break; } } }); // scroll scale stuff SeekBar scrollScale = (SeekBar) findViewById(R.id.scroll_scale); scrollScale.setMax(1000); scrollScale.setProgress(333); scrollScale.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { getSlidingMenu().setBehindScrollScale((float) seekBar.getProgress()/seekBar.getMax()); } }); // behind width stuff SeekBar behindWidth = (SeekBar) findViewById(R.id.behind_width); behindWidth.setMax(1000); behindWidth.setProgress(750); behindWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { float percent = (float) seekBar.getProgress()/seekBar.getMax(); getSlidingMenu().setBehindWidth((int) (percent * getSlidingMenu().getWidth())); getSlidingMenu().requestLayout(); } }); // shadow stuff CheckBox shadowEnabled = (CheckBox) findViewById(R.id.shadow_enabled); shadowEnabled.setChecked(true); shadowEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) getSlidingMenu().setShadowDrawable( getSlidingMenu().getMode() == SlidingMenu.LEFT ? R.drawable.shadow : R.drawable.shadowright); else getSlidingMenu().setShadowDrawable(null); } }); SeekBar shadowWidth = (SeekBar) findViewById(R.id.shadow_width); shadowWidth.setMax(1000); shadowWidth.setProgress(75); shadowWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { float percent = (float) seekBar.getProgress()/ (float) seekBar.getMax(); int width = (int) (percent * (float) getSlidingMenu().getWidth()); getSlidingMenu().setShadowWidth(width); getSlidingMenu().invalidate(); } }); // fading stuff CheckBox fadeEnabled = (CheckBox) findViewById(R.id.fade_enabled); fadeEnabled.setChecked(true); fadeEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { getSlidingMenu().setFadeEnabled(isChecked); } }); SeekBar fadeDeg = (SeekBar) findViewById(R.id.fade_degree); fadeDeg.setMax(1000); fadeDeg.setProgress(666); fadeDeg.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { getSlidingMenu().setFadeDegree((float) seekBar.getProgress()/seekBar.getMax()); } }); }}
关于slidingMenu的所以设置 ,都是在SlidingMenu里面
SlidingMenu sm = getSlidingMenu();
1、setMode
/** Constant value for use with setMode(). Puts the menu to the left of the content. */ public static final int LEFT = 0; /** Constant value for use with setMode(). Puts the menu to the right of the content. */ public static final int RIGHT = 1; /** Constant value for use with setMode(). Puts menus to the left and right of the content. */ public static final int LEFT_RIGHT = 2;
三种侧边栏模式,侧边栏在左边,在右边,两遍都有
在左面或者在右边:
setBehindContentView(R.layout.menu_frame);FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();mFrag = new SampleListFragment();t.replace(R.id.menu_frame, mFrag);t.commit();
LEFT_RIGHT :
sm.setMode(SlidingMenu.LEFT_RIGHT); sm.setSecondaryMenu(R.layout.menu_frame_two); getSupportFragmentManager() .beginTransaction() .replace(R.id.menu_frame_two, new SampleListFragment()) .commit();
2、setTouchModeAbove
设置可拉动触控范围,也是三种
/** Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe * gesture on the screen's margin */ public static final int TOUCHMODE_MARGIN = 0;//边缘 /** Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe * gesture anywhere on the screen */ public static final int TOUCHMODE_FULLSCREEN = 1;//全屏 /** Constant value for use with setTouchModeAbove(). Denies the SlidingMenu to be opened with a swipe * gesture */ public static final int TOUCHMODE_NONE = 2;//关闭
3、setBehindScrollScale
这个是控制侧边栏那个fragment动画的大小,特别是右边的侧边栏,很明显
如果没有这个,就会没有一个从右边慢慢拉出来的动画,简单说就是,有了这个 就有一个侧边栏和首界面是连在一起的,没有这个,就感觉是首页面覆盖在侧边栏上一样
4、setBehindWidth
这个例子当中被隐藏了,其实不要修改也好,这就是侧边栏的宽度,你设置最大宽度之后,就看不到主界面了,只能通过返回键来隐藏侧边栏了
5、setShadowDrawable setSecondaryShadowDrawable
这个就更好理解了,设置有无阴影的
6、setShadowWidth setShadowWidthRes
这个和上面的可以连着用,设置阴影的大小的
7、setFadeEnabled
滑动主界面的时候,侧边栏是否有个遮罩层
8、setFadeDegree
设置那个遮罩的渐变比例
9、setBehindOffsetRes
拉开后离边框距离
10、setSlidingActionBarEnabled
默认是true,ActionBar会随着主界面显示,false,Actionbar不会滚动,一直处于最上面