动作条标签重叠在屏幕旋转 [英] Actionbar Tabs Overlapping on screen rotation

查看:111
本文介绍了动作条标签重叠在屏幕旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关某种原因,当我改变设备的定向,所述动作条没有正确重建和翼片(有时示为一个喷丝)重叠与其他的菜单项。

For some reason, when I change the orientation of the device, the actionbar is not properly rebuilt and the tabs (sometimes shown as a spinner) are overlapped with the other menu items.

我有4个选项卡(它正常工作最多3个)(我用Actionbarsherlock,如果相关) 在肖像,我用图片代替文字的标签。

I have 4 tabs (it works fine up to 3) (I use Actionbarsherlock, if relevant) On portrait, I use images instead of text for the tabs.

下面是截图来说明:

和这里的code我用:

And here's the code I use:

@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();
}

在清单(以防万一,你问,我有这个工作正常):

In Manifest (just in case you ask, I have this working fine):

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

1)我需要的,当然,清洁ovelapping了。

2)如果任何机会,你可以帮我禁用微调,甚至更好。我想唯一的标签,即使我不得不在两个方向使用的图片。

推荐答案

ActionBarSherlock是它存在一个活动的内容视图内的兼容层。这比它存在的正常内容视图内的窗口,但外部的本地操作栏有点不同。

ActionBarSherlock is a compatibility layer which exists inside the content view of an activity. This is a bit different than the native action bar which exists inside the window but outside of the normal content view.

由于这一事实,就不能正确地重新创建自己,当你在你处理方向更改舱单申报。如果prevent ABS的重新操作栏中的看法有几乎总是noticible器物像你想象。

Because of this fact, it cannot properly recreate itself when you declare in the manifest that you handle orientation changes. If you prevent ABS from recreating the action bar views there are almost always noticible artifacts like what you picture.

TL; DR: ActionBarSherlock不与 configChanges =定向

TL;DR: ActionBarSherlock does not work with configChanges="orientation".

这篇关于动作条标签重叠在屏幕旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆