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);
}
你知道我想過更多,如果你沒有爲每個標籤啓動新的活動,我並不真正關注你的佈局,那麼你如何管理「標籤」呢?選項卡如何添加到您的選項卡主機?如果您不使用內置功能,則需要更多代碼才能瞭解如何管理選項卡。 – Jack
我添加了用於設置標籤的代碼 – alexD
哦,廢話,我想我想通了......一秒 - 自從我最初編寫代碼以來,我改變了佈局。我完全忘了setContent() – alexD