2012-01-24 16 views
0

私は5つ以上のタブを必要とするアプリケーションを持っています。私はスクロール可能なタブを作りたいのですが、.tabsが小さくなる.iすべてのタブがHorizo​​ntallScrollViewで同じサイズになるようにします。 これは私の.javaクラス public class ScrolTabsDemoActivity extends TabActivityは、OnTabChangeListenerを実装します。{ /**アクティビティが最初に作成されたときに呼び出されます。 */固定サイズのアンドロイドスクロールタブス

TabHost tabHost; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.main); 
     setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

     Resources res = getResources(); 
     tabHost = getTabHost(); 

     tabHost.setOnTabChangedListener(this); 
     TabHost.TabSpec spec; 
     //Intent intent; 

     Intent intent = new Intent().setClass(this, First.class); 
     spec = tabHost.newTabSpec("First").setIndicator(getString(R.string.shar_tab),res.getDrawable(R.drawable.eshtrkat_1)) 
         .setContent(intent); 
     tabHost.addTab(spec); 

     Intent intent1 = new Intent().setClass(this, Second.class); 
     spec = tabHost.newTabSpec("Second").setIndicator(getString(R.string.wether_tab),res.getDrawable(R.drawable.mkal_1)) 
         .setContent(intent1); 
     tabHost.addTab(spec); 

     Intent intent2 = new Intent().setClass(this, Third.class); 
     spec = tabHost.newTabSpec("Third").setIndicator(getString(R.string.photo_tab),res.getDrawable(R.drawable.img_1)) 
         .setContent(intent2); 
     tabHost.addTab(spec); 

     Intent intent3 = new Intent().setClass(this, Fourth.class); 
     spec = tabHost.newTabSpec("Fourth").setIndicator(getString(R.string.book_tab),res.getDrawable(R.drawable.arshif_1)) 
         .setContent(intent3); 
     tabHost.addTab(spec); 
     Intent intent4 = new Intent().setClass(this, Fivth.class); 
     spec = tabHost.newTabSpec("Fivth").setIndicator(getString(R.string.main_tab),res.getDrawable(R.drawable.news_h)) 
         .setContent(intent4); 
     tabHost.addTab(spec); 


     Intent intent5 = new Intent().setClass(this, Sixth.class); 
     spec = tabHost.newTabSpec("Fivth").setIndicator("tab 6",res.getDrawable(R.drawable.eshtrkat_1)) 
         .setContent(intent5); 
     tabHost.addTab(spec); 

     Intent intent6 = new Intent().setClass(this, Seven.class); 
     spec = tabHost.newTabSpec("Fivth").setIndicator("tab 7",res.getDrawable(R.drawable.game_1)) 
         .setContent(intent6); 
     tabHost.addTab(spec); 
     Intent intent7 = new Intent().setClass(this, Nine.class); 
     spec = tabHost.newTabSpec("Fivth").setIndicator("tab 8",res.getDrawable(R.drawable.mkal_1)) 
         .setContent(intent7); 
     tabHost.addTab(spec); 

     for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 
         { 
         tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#234C09")); 
         } 
         tabHost.setCurrentTab(4); 
         // tabHost.getTabWidget().getChildTabViewAt(4); 
         tabHost.getTabWidget().getChildAt(4).setBackgroundColor(Color.parseColor("#6BE519")); 
} 

@Override 
public void onTabChanged(String tabId) { 
    for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 
    { 
     tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#234C08")); 
    } 

    tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#6ADF17")); 

} }

私はこの答えは、おそらく発見されたことを前提としていますが、このスレッドが現れるので、私は答えるつもりグーグルを検索するときにいくつかの助け

答えて

1

が必要とにかく;-)

一般的に固定サイズを設定するという考えは悪いですが(私はこのテキストが他の人の電話にどれくらいの大きさになるのか分かりません)、私はこの問題を自分で見つけました。これはあなたのTabActivityに次のメソッドを追加解決するには:あなたのOnCreateメソッド呼び出しresizeTabs(tabHost.getTabwidget())の終わりに続いて

関連する問題