2011-06-10 32 views
1

下面的代碼:爲什麼tabbar會在應用程序從背景中返回時向下移動幾個像素?

公共類MenuTabActivity擴展TabActivity實現OnTabChangeListener {

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.menu_layout); 

    TabHost tb = getTabHost(); 

    TabHost.TabSpec spec = null; 
    Intent intent = null; 

    // My Profile tab 
    intent = new Intent(this, MyProfileActivityGroup.class); 

    View myProfileView = LayoutInflater.from(this).inflate(R.layout.button_profil, null); 
    spec = tb.newTabSpec("0").setIndicator(myProfileView).setContent(intent); 
    tb.addTab(spec); 

    // Driving tab 
    intent = new Intent(this, DrivingActivityGroup.class); 
    View drivingView = LayoutInflater.from(this).inflate(R.layout.button_conduite, null); 
    spec = tb.newTabSpec("1").setIndicator(drivingView).setContent(intent); 
    tb.addTab(spec); 

    // Score Tab 
    intent = new Intent(this, ScoreActivityGroup.class); 
    View scoreView = LayoutInflater.from(this).inflate(R.layout.button_score, null); 
    spec = tb.newTabSpec("2").setIndicator(scoreView).setContent(intent); 
    tb.addTab(spec); 

    // Advices Tab 
    intent = new Intent(this, AdvicesActivity.class); 
    View advicesView = LayoutInflater.from(this).inflate(R.layout.button_conseils, null); 
    spec = tb.newTabSpec("3").setIndicator(advicesView).setContent(intent); 

    tb.addTab(spec); 
    tb.setOnTabChangedListener(this); 
    Main.tabBar = tb; 
    tb.setCurrentTab(0); 
} 

@Override 
public void onTabChanged(String tabId) { 

    if (tabId.equals("2")){ 

     //refresh third tab 
     ((ScoreActivityGroup)(getLocalActivityManager().getActivity(tabId))).getScoreActivity().updateView(); 
    } 

    if (tabId.equals("1")){ //driving activity 

     if (Utils.tabImage == null) { 

      //create the static image of the tabbar here 
      Bitmap tabImage = Bitmap.createBitmap(getTabHost().getTabWidget().getWidth(), getTabHost().getTabWidget().getHeight(), Bitmap.Config.RGB_565); 
      getTabHost().getTabWidget().draw(new Canvas(tabImage)); 
      Utils.tabImage = tabImage; 
     } 

     //load second "tab" Activity 
     ((DrivingActivityGroup)(getLocalActivityManager().getActivity("1"))).startDrivingActivity(); 
    } 

    if (!tabId.equals("2")){ 

     if (getLocalActivityManager().getActivity("2") != null){ 

      if (((ScoreActivityGroup)getLocalActivityManager().getActivity("2")).getCurrentActivity() instanceof ScoreDetailsActivity){ 

       //dismiss Conseil Dialog if it exists 
       ((ScoreDetailsActivity)(((ScoreActivityGroup)getLocalActivityManager().getActivity("2")).getCurrentActivity())).dismissConseilDialog(); 
      } 
     } 
    } 
} 

/** 
* This method starts an activity with a given animation (ex: bottom-top) 
* Used for info activities 
* 
* This action is placed here because the animations are ignored if done 
* from child activities of the MenuTabActivity. 
* 
* @param clazz 
* @param enterAnim 
* @param exitAnim 
* @param intentExtra 
*/ 
public void startActivityWithOverridePendingTransition(Class<?> clazz, int enterAnim, int exitAnim, Integer intentExtra){ 
    final Intent intent = new Intent(this, clazz); 
    if (intentExtra != null){ 
     intent.putExtra("com.renault.Intent", intentExtra); 
    } 
    startActivity(intent); 
    overridePendingTransition(enterAnim, exitAnim); 
} 

public void onDestroy(){ 
    super.onDestroy(); 

    if (Main.monitoringHasStarted) { 

     Main.DriveBusinessService.stopMonitoring(); 
     ScoringModelPojo.saveToBundle(getApplicationContext()); 
    } 

    Main.monitoringHasStarted = false; 

    SettingsModel.saveToBundle(getApplicationContext()); 
} 

} `

這裏的tabwidget:

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight = "1"/> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background = "@color/grayFond" 
      android:layout_weight = "0"/> 
    </LinearLayout> 
</TabHost> 

沒有任何的你遇到的標題中提到的問題?

+0

笏你想知道嗎?標題中明確規定了該問題 – Hussain 2011-06-10 12:11:41

+0

。你的困惑在哪裏? – 2011-06-10 12:13:45

+0

最初你們發佈了ur代碼,所以只有 – Hussain 2011-06-10 12:19:12

回答

0

我發現出了什麼問題。它一定是一個bug。在清單文件中,我沒有狀態欄和全屏。將狀態欄返回到屏幕時,(NO FULLSCREEN)按照它應該的方式工作。也許這有助於某人。

PS。這應該作爲與ANDROID的錯誤提交。 (在2.1中測試)

相關問題