简体   繁体   English

NAVIGATION_MODE_TABS和ViewPager在横向上无法正常工作

[英]NAVIGATION_MODE_TABS and ViewPager not working properly in landscape orientation

I have an activity which contains a viewpager to swipe across 4 fragments. 我有一个活动,其中包含一个可在4个片段上滑动的viewpager。 I'm also using ActionBar.NAVIGATION_MODE_TABS to display the tabs name and allow navigating by pressing on on the tab as well as swiping 我还使用ActionBar.NAVIGATION_MODE_TABS来显示选项卡名称,并通过在选项卡上按下和滑动来进行导航

    public void onCreate(Bundle savedInstanceState) {
...
        this.viewPager = (ViewPager) findViewById(R.id.viewPager);
        this.viewPagerAdapter = new MyViewPagerAdapter(this, getSupportFragmentManager());
        this.viewPager.setAdapter(this.viewPagerAdapter);
        this.viewPager.setCurrentItem(0);

        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            // Create a tab listener that is called when the user changes tabs.
            final TabListener tabListener = new TabListener() {

                @Override
                public void onTabReselected(Tab arg0, FragmentTransaction arg1) {

                }

                @Override
                public void onTabSelected(Tab tab, FragmentTransaction arg1) {
                        viewPager.setCurrentItem(tab.getPosition());
                    }
                }

                @Override
                public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
                }
            };


// add the tabs

            this.viewPager.setOnPageChangeListener(
                    new ViewPager.SimpleOnPageChangeListener() {
                        @Override
                        public void onPageSelected(int position) {
                                // When swiping between pages, select the corresponding tab.
                                actionBar.setSelectedNavigationItem(position);
                        }
                    });

This works fine, but when the device is in landscape orientation, the tabs are displayed as an action spinner, then the spinner content doesn't refresh anymore when swiping in the viewpager even though onPageSelected() is called with the correct position 这可以正常工作,但是当设备处于横向时,选项卡将显示为动作微调器,即使在正确位置调用onPageSelected()时,在viewpager中滑动时微调器的内容也不会刷新

Any idea how to fix this ? 任何想法如何解决这个问题?

Thanks 谢谢

For now I will use the following workaround, but I'm still interested in finding a real solution. 现在,我将使用以下解决方法,但是我仍然对寻找一个真正的解决方案感兴趣。 The workaround is to force the display of the tabs even in landscape by setting the navigation mode after the tabs have been added as seen here 解决方法是通过设置导航模式迫使选项卡的显示,即使在景观后所看到的标签已被添加在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 navigation_mode_tabs垂直无法正常工作 - navigation_mode_tabs vertical is not working 之前调用Fragment的onStart()来显示Viewpager,navigation_mode_tabs - Call onStart() of Fragment before to display Viewpager, navigation_mode_tabs 如何在主/详细片段中获取支持操作栏以设置NAVIGATION_MODE_TABS? - How to get Support Action Bar inside a Master/Detail Fragment to set NAVIGATION_MODE_TABS? ActionbarSherlock - 横向选项卡无响应 - ActionbarSherlock - tabs unresponsive in landscape orientation 动作栏标签会自动切换到横向模式下的列表 - actionbar tabs auto switch to list in landscape mode 使用ViewPager和导航抽屉的操作栏选项卡 - Action Bar Tabs using ViewPager with Navigation Drawer 如何仅针对平板电脑以横向方向删除ActionBar选项卡 - How to remove ActionBar tabs in landscape orientation only for tablets Sherlock选项卡无法更改方向 - Sherlock tabs not working on orientation change 带有导航标签的ActionBar会根据屏幕方向更改高度 - ActionBar with navigation tabs changes height with screen orientation 同时使用ActionBar.NAVIGATION_MODE_TABS和ActionBar.NAVIGATION_MODE_LIST - Using ActionBar.NAVIGATION_MODE_TABS together with ActionBar.NAVIGATION_MODE_LIST
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM