一、DrawerLayout 谷歌官方提供html
(1) https://developer.android.com/training/implementing-navigation/nav-drawer.htmlandroid
下載它的demo,導入運行。ide
(2)Support v4 Demos---->Widget----->Drawer layouthtm
(3)實現手勢滑動:get
FrameLayout content_frame=(FrameLayout)findViewById(R.id.content_frame);
content_frame.setOnTouchListener(new OnTouchListener() {
float startX ;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startX = event.getX();
break;
case MotionEvent.ACTION_UP:
if (event.getX() > startX) { // 向右滑動
/*if (!mDrawerLayout.isDrawerVisible(GravityCompat.START)) {
}*/
mDrawerLayout.openDrawer(GravityCompat.START);
mDrawerLayout.setDrawerListener(mDrawerToggle);
} else if (event.getX() < startX) { // 向左滑動
mDrawerLayout.closeDrawer(GravityCompat.START);
}
break;
}
return true;
}
});it