操作栏选项卡重叠屏幕旋转

时间:2013-07-04 02:20:50

标签: android android-layout actionbarsherlock android-actionbar

出于某种原因,当我更改设备的方向时,操作栏未正确重建,并且标签(有时显示为微调器)与其他菜单项重叠。

我有4个标签(最多3个可以正常工作)(我使用Actionbarsherlock,如果相关的话) 在肖像上,我使用图像而不是文本作为标签。

这是一个截图来解释:

http://i39.tinypic.com/2vkzuix.jpg

这是我使用的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    // Set up the action bar.
    actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setEnabled(false);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(3);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    }); 

    RebuildActionBar();
}

public void RebuildActionBar(){
    if(actionBar.getTabCount()>0) actionBar.removeAllTabs();
    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        if(screen_width>screen_height){
            actionBar.addTab(actionBar.newTab()
                .setText(mSectionsPagerAdapter.getPageTitle(i))
                .setTabListener(this));
        } else {
            actionBar.addTab(actionBar.newTab()
                    .setIcon(mSectionsPagerAdapter.getPageIcon(i))
                    .setTabListener(this));
        }
    }
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    RebuildActionBar();
}

在Manifest中(以防你问,我的工作正常):

<activity
    ...
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
/>

1)当然,我需要清理过度。

2)如果你有任何机会可以帮助我禁用旋转器,甚至更好。我只想要标签,即使我必须在两个方向都使用图像。

1 个答案:

答案 0 :(得分:3)

ActionBarSherlock是一个兼容层,它存在于活动的内容视图中。这与窗口内但在普通内容视图之外的本机操作栏略有不同。

由于这个事实,当您在清单中声明处理方向更改时,它无法正确地重新创建。如果你阻止ABS重新创建操作栏视图,那么几乎总会出现像你所描绘的那样的神器。

TL; DR: ActionBarSherlock不适用于configChanges="orientation"

相关问题