Din*_*dha 10 android android-viewpager actionbarsherlock drawerlayout
我已经实现ViewPager一个内部DrawerLayout它工作正常,但抽屉菜单列表视图中不与操作栏就会显示ViewPager tabs.Hope下图下面会给你一个想法正确显示.我正在使用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"),Fragment.class, null);
mTabsAdapter.addTab(mActionBar.newTab().setText("Fragment"),Fragment.class, null);
mTabsAdapter.addTab(mActionBar.newTab().setText("Fragment"),Fragment.class, null);
Run Code Online (Sandbox Code Playgroud)
活动布局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>
Run Code Online (Sandbox Code Playgroud)
这是抽屉与操作栏选项卡的行为。你无法改变它。
在这个答案中找到一些官方信息:Android Navigation Drawer over the tabs
以及此答案中的解决方法:Getting DrawerLayout to Slide over the ActionBar
我会考虑使用这个很棒的库:PagerSlidingTabStrip
| 归档时间: |
|
| 查看次数: |
11428 次 |
| 最近记录: |