2012-02-21 8 views
1

タブバーに4つのタブがあります。アプリケーションを起動するときはいつでも、タブバーのすべてのタブ(4つ)を実行する必要があります。なぜなら、すべてのタブには、アプリが起動されるたびに読み込まれるべきWebviewが含まれているからです。しかし、最初のタブが強調表示されるはずです。私は最初のタブをロードするのに、残りのタブをクリックすることなくロードすることができませんでしたタブバーのすべてのタブを同時にAndroidに読み込む方法

setCurrentTab(0); 

を使用しました。

答えて

0

これを行うには、まずxmlファイルを作成します。サンプルファイルは以下の通りです。

<?xml version="1.0" encoding="utf-8"?> 
<TabHost android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:id="@android:id/tabhost" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:background="@drawable/background"> 
    <TabWidget android:layout_width="fill_parent" android:id="@android:id/tabs" 
     android:layout_height="wrap_content" /> 
    <FrameLayout android:layout_width="fill_parent" android:id="@android:id/tabcontent" 
     android:layout_gravity="bottom" android:paddingTop="70dp" 
     android:layout_height="match_parent"> 

    <ScrollView android:layout_height="fill_parent" android:id="@+id/viewTab1" 
     android:layout_width="match_parent"> 
     <!-- Your view you want --> 

    </ScrollView> 
    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:id="@+id/viewTab2"> 
     <!-- Your view you want --> 

    </LinearLayout> 

    <!-- Add as many view you want with unique id --> 
</FrameLayout> 

各レイアウトは、独自のレイアウトを参照します。

TabHost tabHost = getTabHost(); 
TabSpec spec1 = tabHost.newTabSpec("FirstTabView"); 
TabSpec spec2 = tabHost.newTabSpec("SecondTabView"); 

spec1.setContent(R.id.viewTab1); 
spec1.setIndicator("First Tab"); 

spec2.setIndicator("Second Tab"); 
spec2.setContent(R.id.viewTab2); 

tabHost.addTab(spec1); 
tabHost.addTab(spec2); 

tabHost.setup(); 

あなたが必要として多くのタブを追加することができ、次の主な活動の使用では

。これはすべて同時に初期化されます。

私はこれがあなたを助けてくれることを願っています:)

関連する問題