繁体   English   中英

为什么此TextView出现在我的两个TabPage上? 它应该只在第一个

[英]Why is this TextView showing up on both of my TabPages? It should only be on the first

我有一个TextView只应该显示在第一个TabPage (包含ScrollView )中,但是由于某种原因,它同时显示在我的两个TabPages ,而TableLayout像应该显示的那样仅显示在第一个TabPage中。 我不知道为什么...这里是我的XML文件:有问题的TextView是ScrollView中的'primaryInfo'。

<?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);
}

好吧,问题是当我更改布局时,由于该选项卡页面的顶级视图发生了更改,因此我忘记更改了传递给setContent方法的View。 这是我更改布局之前的样子(它本来可以工作):

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");

问题解决了。 感谢Jack让我发布代码,因为那是我最后注意到它的时候;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM