我已经在DrawerLayout中实现了ViewPager,它正常工作,但是Drawer菜单列表视图没有正确显示,它将显示在ViewPager选项卡下方的操作栏中.希望下面的图将给你一个想法.
我正在使用actionbarsherlock库.
我正在使用actionbarsherlock库.
我曾尝试过
活动OnCreate():
setContentView(R.layout.activity_layout); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); mLinearLayout = (LinearLayout)findViewById(R.id.ll_viewpager_layout); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); mDrawerToggle = new ActionBarDrawerToggle( this,/* host Activity */ mDrawerLayout,/* DrawerLayout object */ R.drawable.ic_drawer,/* nav drawer image to replace 'Up' caret */ R.string.app_name,/* "open drawer" description for accessibility */ R.string.app_you /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { } public void onDrawerOpened(View drawerView) { } }; mDrawerLayout.setDrawerListener(mDrawerToggle); invalidateMenuItems(); mViewPager = new ViewPager(this); mViewPager.setOnPageChangeListener(this); mViewPager.setId(1); mViewPager.setOffscreenPageLimit(7); mLinearLayout.addView(mViewPager); mTabsAdapter = new TabsAdapter(this,mViewPager,mActionBar); mTabsAdapter.addTab(mActionBar.newTab().setText("Fragment"),Fragment.class,null); mTabsAdapter.addTab(mActionBar.newTab().setText("Fragment"),null);
活动布局xml:
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/ll_dashboard_viewpager" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" /> <ListView android:id="@+id/left_drawer" android:layout_width="200dip" android:layout_height="match_parent" android:layout_gravity="start" android:background="@color/abs__background_holo_light" android:cacheColorHint="#00000000" android:choiceMode="singleChoice" android:dividerHeight="1dip" /> </android.support.v4.widget.DrawerLayout>
解决方法
这是抽屉的行为与动作栏选项卡.你不能改变它.
在这个答案中找到一些官方信息:Android Navigation Drawer over the tabs
和答案的解决办法:Getting DrawerLayout to Slide over the ActionBar
我会考虑使用这个伟大的图书馆:PagerSlidingTabStrip