Android 两个XML文件,但其中一个在应用程序运行时未显示在应用程序中

Android 两个XML文件,但其中一个在应用程序运行时未显示在应用程序中,android,xml,android-activity,Android,Xml,Android Activity,我在res>layout文件夹中创建了一个名为tabs.xml的新xml文件。其代码如下: <?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

我在res>layout文件夹中创建了一个名为tabs.xml的新xml文件。其代码如下:

    <?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="@android: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" >

                <RelativeLayout
                    android:id="@+id/Network"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <TextView
                        android:id="@+id/textView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"
                        android:text="Channel Type:"
                        android:textAppearance="?android:attr/textAppearanceMedium" />

                    <RadioButton
                        android:id="@+id/urbanButton1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/textView1"
                        android:text="Urban" />

                     <RadioButton
                         android:id="@+id/suburbanButton2"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_alignBaseline="@+id/urbanButton1"
                         android:layout_alignBottom="@+id/urbanButton1"
                         android:layout_centerHorizontal="true"
                         android:text="SubUrban" />

                     <RadioButton
                         android:id="@+id/ruralButton3"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_alignBaseline="@+id/suburbanButton2"
                         android:layout_alignBottom="@+id/suburbanButton2"
                         android:layout_alignParentRight="true"
                         android:layout_marginRight="15dp"
                         android:text="Rural" />

                     <TextView
                         android:id="@+id/textView2"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_below="@+id/urbanButton1"
                         android:text="Characteristics of Channel:"
                         android:textAppearance="?android:attr/textAppearanceMedium" />

                     <TextView
                         android:id="@+id/textView3"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_alignParentLeft="true"
                         android:layout_alignRight="@+id/suburbanButton2"
                         android:layout_below="@+id/textView2"
                         android:text="Medium Text"
                         android:textAppearance="?android:attr/textAppearanceMedium" />

                     <CheckBox
                         android:id="@+id/checkBox1"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_below="@+id/textView3"
                         android:layout_toLeftOf="@+id/ruralButton3"
                         android:text="Manual Override" />
                 </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/power"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/Connectivity"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/Offline"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </RelativeLayout>
            </FrameLayout>
        </LinearLayout>`enter code here`
    </TabHost>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.qosmetre"
android:versionCode="1"
android:versionName="1.0" >

  <uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="17" />

  <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.qosmetre.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  <activity 
        android:name=".MyTabsActivity" 
        </activity> 
  </application>`enter code here`

</manifest>
现在我的问题是,当我在终端上或在调试模式下运行我的应用程序时,为什么除了一个空白屏幕外什么都没有显示?就像我希望标签首先显示出来,下面有所有的东西,如代码所示。另外,我如何为我的应用程序中的散点绘图数据导入库

我需要知道在哪里和什么文件中放什么代码,因为我只是一个初学者,我不知道太多,所以我需要大的指南

提前再次感谢

My android Manifest.xml包含以下代码:

    <?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="@android: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" >

                <RelativeLayout
                    android:id="@+id/Network"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <TextView
                        android:id="@+id/textView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"
                        android:text="Channel Type:"
                        android:textAppearance="?android:attr/textAppearanceMedium" />

                    <RadioButton
                        android:id="@+id/urbanButton1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/textView1"
                        android:text="Urban" />

                     <RadioButton
                         android:id="@+id/suburbanButton2"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_alignBaseline="@+id/urbanButton1"
                         android:layout_alignBottom="@+id/urbanButton1"
                         android:layout_centerHorizontal="true"
                         android:text="SubUrban" />

                     <RadioButton
                         android:id="@+id/ruralButton3"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_alignBaseline="@+id/suburbanButton2"
                         android:layout_alignBottom="@+id/suburbanButton2"
                         android:layout_alignParentRight="true"
                         android:layout_marginRight="15dp"
                         android:text="Rural" />

                     <TextView
                         android:id="@+id/textView2"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_below="@+id/urbanButton1"
                         android:text="Characteristics of Channel:"
                         android:textAppearance="?android:attr/textAppearanceMedium" />

                     <TextView
                         android:id="@+id/textView3"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_alignParentLeft="true"
                         android:layout_alignRight="@+id/suburbanButton2"
                         android:layout_below="@+id/textView2"
                         android:text="Medium Text"
                         android:textAppearance="?android:attr/textAppearanceMedium" />

                     <CheckBox
                         android:id="@+id/checkBox1"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_below="@+id/textView3"
                         android:layout_toLeftOf="@+id/ruralButton3"
                         android:text="Manual Override" />
                 </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/power"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/Connectivity"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/Offline"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </RelativeLayout>
            </FrameLayout>
        </LinearLayout>`enter code here`
    </TabHost>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.qosmetre"
android:versionCode="1"
android:versionName="1.0" >

  <uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="17" />

  <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.qosmetre.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  <activity 
        android:name=".MyTabsActivity" 
        </activity> 
  </application>`enter code here`

</manifest>


有关详情,请参阅

不赞成:
TabActivity
自API级别13以来已被弃用

对于针对蜂巢或更高版本开发的应用程序,选项卡通常显示在 使用新ActionBar.newTab()和相关API放置 选项卡位于其操作栏区域内

截图:

tabs.xml
: 在下面的评论中回答您的问题: “我基本上想要4个不同名称的标签,然后在每个标签中 这些标签我需要不同的文本框,复选框等,以及 请记住,选项卡中不会包含ame内容 他们“

您正在以编程方式添加选项卡。如果要附加整个
布局
,请定义布局(例如在
线性布局
框架布局
,等等),然后以编程方式将其添加到
.java
代码中

您的
tabs.xml
具有以下结构:


从上面的结构图中可以看到,xml代码只有在
中才有对象(例如TextView、RadioButton等),它表示类型MainActivity的方法gettabHost()未定义。“在这里输入代码”是什么意思。我不知道在那里输入什么代码。很抱歉这样noob@user2159721我修改了我的答案。你能再试一次吗?是的,有。有什么方法可以发送屏幕截图吗?应该是tabs extends tabactivity还是tabs extends Activity请添加您的导入语句:
import android.app.tabactivity在您的
AndroidManifest.xml
中添加

package com.example.qosmetre;

import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;

public class Tabs extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabs);

        // we start adding the tabs programmatically
        TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost);

        mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Network")
                .setContent(R.id.Network));
        mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Power")
                .setContent(R.id.Power));
        mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Connectivity")
                            .setContent(R.id.Connectivity));
        mTabHost.addTab(mTabHost.newTabSpec("tab4").setIndicator("Offline")
                .setContent(R.id.Offline));

        mTabHost.setCurrentTab(0); // sets default tab
    }
    // more methods
}
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Network")
            .setContent(R.id.Network));