2011-10-13 28 views
0

我有一個TextView,只應該顯示在第一個TabPage(其中包含ScrollView),但由於某種原因它出現在我的兩個TabPages,而TableLayout只顯示在第一個TabPage喜歡它應該。我不知道爲什麼......這是我的XML文件:問題中的TextView是ScrollView中的'primaryInfo'。爲什麼這個TextView出現在我的兩個TabPages上?它應該只在第一個

<?xml version="1.0" encoding="utf-8"?> 
<TabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tabHost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

    <TabWidget 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@android:id/tabs"> 
     </TabWidget> 

     <FrameLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:id="@android:id/tabcontent"> 

      <ScrollView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/scrollView"> 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:text="Primary Info" 
         android:layout_marginTop="15dp" 
         android:layout_marginBottom="15dp" 
         android:gravity="center_horizontal" 
         android:id="@+id/piTextView" 
         android:background="#595959"/> 

        <TableLayout 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:id="@+id/specsTab" 
         android:layout_centerHorizontal="true"/> 

       </LinearLayout> 
      </ScrollView> 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" 
       android:id="@+id/photosTab"> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_above="@+id/thumbnailGallery" 
        android:id="@+id/selectedPhoto"/> 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/imageProgressLayout" 
        android:layout_alignParentBottom="true" 
        android:orientation="horizontal"> 

        <ProgressBar 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         style="@android:style/Widget.ProgressBar.Small" 
         android:indeterminate="true" 
         android:layout_marginTop="5dp" 
         android_layout_marginLeft="20dp" 
         android_layout_marginBottom="20dp" 
         android:id="@+id/galleryProgress"/> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="fill_parent" 
         android:id="@+id/loadingTextView" 
         android:text="Loading images..." 
         android:layout_marginLeft="5dp" 
         android:layout_centerVertical="true" 
         android:textSize="13sp"/>   
       </LinearLayout> 

       <Gallery 
        android:id="@+id/thumbnailGallery" 
        android:layout_above="@+id/galleryProgress" 
        android:layout_width="fill_parent" 
        android:layout_alignParentBottom="true" 
        android:layout_marginBottom="10dp" 
        android:layout_height="wrap_content"/> 

      </RelativeLayout> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 

編輯

選項卡設置代碼:

public void tabSetup() 
{ 
    TabHost tabHost=(TabHost)findViewById(R.id.tabHost); 
    tabHost.setup(); 

    TextView tv1 = new TextView(this); 
    tv1.setText("Specs"); 
    tv1.setHeight(50); 

    TextView tv2 = new TextView(this); 
    tv2.setText("Photos"); 
    tv2.setHeight(50); 

    TabSpec spec1=tabHost.newTabSpec("Specs"); 
    spec1.setContent(R.id.specsTab); 
    spec1.setIndicator("Specs"); 

    TabSpec spec2=tabHost.newTabSpec("Photos"); 
    spec2.setIndicator("Photos"); 
    spec2.setContent(R.id.photosTab); 

    tabHost.addTab(spec1); 
    tabHost.addTab(spec2); 
} 
+1

你知道我想過更多,如果你沒有爲每個標籤啓動新的活動,我並不真正關注你的佈局,那麼你如何管理「標籤」呢?選項卡如何添加到您的選項卡主機?如果您不使用內置功能,則需要更多代碼才能瞭解如何管理選項卡。 – Jack

+0

我添加了用於設置標籤的代碼 – alexD

+0

哦,廢話,我想我想通了......一秒 - 自從我最初編寫代碼以來,我改變了佈局。我完全忘了setContent() – alexD

回答

0

好了,問題是,當我改變了佈局,我忘了改,我傳遞到setContent方法查看因爲該標籤頁的頂層視圖已更改。下面是它是什麼之前,我改變了佈局(和它最初的工作):

TabSpec spec1=tabHost.newTabSpec("Specs"); 
spec1.setContent(R.id.specsTab); 
spec1.setIndicator("Specs"); 

,這就是它需要與當前的佈局,我張貼上面:

TabSpec spec1=tabHost.newTabSpec("Specs"); 
spec1.setContent(R.id.scrollView); 
spec1.setIndicator("Specs"); 

問題解決了。感謝傑克讓我發佈代碼,因爲那是當我最終注意到它的時候);

相關問題