1,DrawerLayout 用法:直接在XML中定义
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical">
</FrameLayout>
<FrameLayout
android:id="@+id/main_left"
android:layout_width="350dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#F00000"
android:orientation="vertical">
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
2,DrawerLayout 嵌套Fragment的话
getFragmentManager().beginTransaction().add(R.id.FragmentContainer,new HomeFragment()).commit();
3, SlidingMenu 代码用法
public class ReportActivity extends SlidingFragmentActivity {
private SlidingMenu mMenu;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setBehindContentView(R.layout.activity_menu);
setContentView(R.layout.activity_content);
mMenu = getSlidingMenu();
mMenu.setMode(SlidingMenu.LEFT); //左边菜单
mMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); // 菜单栏的触摸模式
mMenu.setBehindOffsetRes(R.dimen.menu_behindOff); //宽度
mMenu.setShadowDrawable(R.color.colorPrimaryDark);
mMenu.setShadowWidthRes(R.dimen.menu_shadowWidth);
}
}