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