2015-09-04 60 views
0

我創建活動包含tabhost有3個標籤,還定義TabHost方向改變

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"> 
在清單的改變的定向

,它可以幫助我繼續留在橫向模式相同的標籤。但是當我創建一個新的橫向模式的XML文件,我把它放到res/layout-land。我的問題是當我進入第二個或第三個標籤並改變爲橫向模式時,它調用中的xml layout- land但標籤主機切換到第一個標籤。很好地幫助我。 謝謝。

回答

0

覆蓋@onSaveInstance來保存當前選項卡的位置會更好。

而且在onCreate方法可以檢查的位置,並根據位置

@Override 
public void onSaveInstanceState(Bundle savedInstanceState) { 
    // Save the current position of the tab 
    savedInstanceState.putInt(CURRENT_TAB, getTabHost().getCurrentTab()); 
    super.onSaveInstanceState(savedInstanceState); 
} 

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

    // Check for the tabPosition Value 
    if (savedInstanceState != null) { 
    // Restore tab position from saved state and set to TaBHost 
    mCurrentTab= savedInstanceState.getInt(CURRENT_TAB); 
    } 
    //initialize the tabHost and tab 
    tabHost.setCurrentTab(mCurrentTab); 
設置選項卡