1
2
3
4
5
|
setBehindContentView(R.layout.menu_frame);
FragmentTransaction t =
this
.getSupportFragmentManager().beginTransaction();
leftMenuFragment =
new
MenuFragment();
t.replace(R.id.menu_frame, leftMenuFragment);
t.commit();
|
1
2
3
4
5
6
7
8
9
10
11
|
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();
|
1
2
3
4
5
6
7
8
9
10
11
|
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);
|
1
2
3
4
5
6
7
|
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
);
}
};
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
private
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;
}
};
|
1
2
3
4
5
6
|
mTransformer =
new
CanvasTransformer() {
@Override
public
void
transformCanvas(Canvas canvas,
float
percentOpen) {
canvas.scale(percentOpen,
1
,
0
,
0
);
}
});
|