Android 为什么我的选项卡视图是透明的?

Android 为什么我的选项卡视图是透明的?,android,android-layout,Android,Android Layout,正在编写新的波士顿教程(如果你知道有人想学习android,我强烈推荐)。我目前正在处理标签。我有一些设置,但你可以看到和互动的所有标签内容后面的一个“顶部”。我怎样才能阻止它?我试着在组成每个选项卡的每个线性布局中添加一个背景,但所做的只是让它们在不同颜色的背景下清晰可见。底部的图像在顶部显示左侧选项卡,但第二个和第三个选项卡中的按钮/文本视图显示到。我需要每个选项卡只显示该选项卡中的内容,而不是顶部选项卡后面的选项卡中的内容 爪哇: XML: 它看起来像什么: 如果不知道布局应该是什么样

正在编写新的波士顿教程(如果你知道有人想学习android,我强烈推荐)。我目前正在处理标签。我有一些设置,但你可以看到和互动的所有标签内容后面的一个“顶部”。我怎样才能阻止它?我试着在组成每个选项卡的每个线性布局中添加一个背景,但所做的只是让它们在不同颜色的背景下清晰可见。底部的图像在顶部显示左侧选项卡,但第二个和第三个选项卡中的按钮/文本视图显示到。我需要每个选项卡只显示该选项卡中的内容,而不是顶部选项卡后面的选项卡中的内容

爪哇:

XML:


它看起来像什么:


如果不知道布局应该是什么样子,很难给出建议。然而,您看到的是将多个项目放置在基本上允许重叠的
框架布局中的副作用。至于透明度,大多数安卓“视图”的设计都有一定的透明度——只是在覆盖它们之前,你通常不会注意到它。@Squonk我已经添加到我的主要问题中了。布局本身很好,但您看到的是所有3个选项卡的内容。我需要它只显示当前选项卡中的内容,在您创建
TabSpec
onCreate(…)
方法中,而不是重复使用
spec
尝试使用3个不同的
TabSpec
对象。换句话说…
TabSpec spec1=th.newTabSpec(“tag1”)
然后
TabSpec spec2=…
TabSpec spec3=…
@Squonk刚刚尝试了它,没有运气,我没有任何其他想法,尽管这是一个指向选项卡式应用程序示例的链接-也许可以尝试遵循其中的布局结构。它将
TabHost
作为根视图,而不是像您所做的那样将其放入
LinearLayout
中。
    package com.thenewboston.psest328;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TabHost;
    import android.widget.TabHost.TabSpec;
    import android.widget.TextView;

    public class Tabs extends Activity implements OnClickListener {

        TabHost th;
        Button newTab, bStart, bStop;
        TextView showResults;
        long start;
        long stop;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.tabs);

            th = (TabHost)findViewById(R.id.tabhost);
            newTab = (Button)findViewById(R.id.bAddTab);
            bStart = (Button)findViewById(R.id.bStartWatch);
            bStop = (Button)findViewById(R.id.bStopWatch);
            showResults = (TextView)findViewById(R.id.tvShowResults);
            th.setup();

            newTab.setOnClickListener(this);
            bStart.setOnClickListener(this);
            bStop.setOnClickListener(this);

            TabSpec spec = th.newTabSpec("tag1");
            spec.setContent(R.id.tab1);
            spec.setIndicator("StopWatch");
            th.addTab(spec);

            spec = th.newTabSpec("tag2");
            spec.setContent(R.id.tab2);
            spec.setIndicator("Tab 2");
            th.addTab(spec);

            spec = th.newTabSpec("tag3");
            spec.setContent(R.id.tab2);
            spec.setIndicator("Add Tab");
            th.addTab(spec);
        }

        @Override
        public void onClick(View view) {

        // TODO Auto-generated method stub
        switch(view.getId()) {
        case R.id.bAddTab:

            TabSpec ourSpec = th.newTabSpec("tag1");
            ourSpec.setContent(new TabHost.TabContentFactory() {

                @Override
                public View createTabContent(String tag) {
                    // TODO Auto-generated method stub

                    TextView text = new TextView(Tabs.this);
                    text.setText("You've created a new tab");
                    return text;
                }
            });
            ourSpec.setIndicator("New");
            th.addTab(ourSpec);

            break;

        case R.id.bStartWatch:
            start = 0;
            start = System.currentTimeMillis();
            break;

        case R.id.bStopWatch:
            stop = System.currentTimeMillis();

            if(start != 0) {
                long result = stop - start;
                showResults.setText(Long.toString(result));
            }
            break;
        }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TabHost
        android:id="@+id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

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

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

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

                <LinearLayout
                    android:id="@+id/tab1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <Button
                        android:id="@+id/bStartWatch"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Start" />

                    <Button
                        android:id="@+id/bStopWatch"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Stop" />

                    <TextView
                        android:id="@+id/tvShowResults"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="TextView" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="TextView 3" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <Button
                        android:id="@+id/bAddTab"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Add Tab" />                    

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