[英]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.