2011-11-22 52 views
-1

我已經實現了4個選項卡,每個選項卡都有一個與之關聯的活動。建議刪除/替換這些活動以獲得更好的應用程序性能?如果是,那麼該怎麼做?如何刪除/替換android中的選項卡活動?

+2

你通過刪除的意思/替換這些活動?你在談論什麼性能提升? – LuxuryMode

+0

我給出了答案。我真的不知道它是否完全回答你的問題,但如果你需要更多的啓發或什麼,然後只是評論我的答案,我會看看我能否提供幫助。 – Jakar

回答

0

我真的懷疑有3個標籤而不是4會明顯改變性能。您需要擁有與適合您的應用程序一樣多的選項卡。在我的應用程序中,我需要4個選項卡,因爲如果我有3個選項卡,那麼使用能力會很差,導航會很困難。
如果你想要5個標籤,那麼我建議不要使用tabwidget,然後實現自己的自定義佈局(可能是水平滾動視圖),就像在WeatherBug中實現的那樣。然後在該自定義佈局上,在每個按鈕或圖像視圖或任何您的自定義佈局中,您都可以在onClick中調用setCurrentTab來查看視圖。

而且我有4個選項卡是這樣的:

intent = new Intent().setClass(this, ActivityTabOther.class); 
     spec = tabHost.newTabSpec("other").setIndicator("General", 
          res.getDrawable(R.drawable.other)) 
         .setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, ActivityTabLocate.class); 
     spec = tabHost.newTabSpec("locate").setIndicator("Locate", 
          res.getDrawable(R.drawable.locate)) 
         .setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, ActivityTabSecure.class); 

     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabHost.newTabSpec("secure").setIndicator("Secure", 
          res.getDrawable(R.drawable.secure)) 
         .setContent(intent); 
     tabHost.addTab(spec); 
     //If you want to remove a tab, delete everything from here down, and that's minus one tab. 
     intent = new Intent().setClass(this, ActivityTabFriends.class); 
     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabHost.newTabSpec("friends").setIndicator("Friends", 
          res.getDrawable(R.drawable.findabuddy)) 
         .setContent(intent); 
     tabHost.addTab(spec); 
相關問題