3

res>layout forlder に 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>

今、私は何も追加していない同じフォルダーにandroid activity_main.xmlも持っています。また、Tabs.Java という Java ファイルを作成し、次のコードを使用して src>com.example.qosmetre>Tabs.Java の下の src フォルダーに配置しました。

package com.example.qosmetre;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Tabs extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabs);
    }

}

私の質問は、ターミナルまたはデバッグモードでアプリを実行すると、空白の画面以外に何も表示されないのはなぜですか? コードに示されているように、タブの下にあるすべてのものを最初に表示するようにします。また、アプリにある散布図データのライブラリをインポートするにはどうすればよいですか?

私は初心者であり、あまりにも多くのことを知らないので、大きなガイドが必要なので、どこにどのファイルにどのコードを入れるかを知る必要があります。

よろしくお願いします。

私のandroid Manifest.xmlには次のコードがあります:

<?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>
4

1 に答える 1

0

詳細については、TabActivity Android APIを参照してください。

非推奨:

TabActivityAPI レベル 13 から非推奨になりました。

HONEYCOMB 以降で開発されているアプリの場合、タブは通常、新しい ActionBar.newTab() と、アクション バー領域内にタブを配置するための関連 API を使用して UI に表示されます。

スクリーンショット:

スクリーンショット

tabs.xml:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_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>

</TabHost>

MyTabsActivity.java:

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
}

以下のコメントであなたの質問に答えるには:

「私は基本的に、異なる名前の 4 つのタブが必要です。そして、それらのタブのそれぞれに、異なるテキストボックス、チェックボックスなど、およびグラフが必要です。タブには、それらの内部に ame が含まれないことに注意してください」

プログラムでタブを追加しています全体をアタッチしたい場合はlayout、レイアウトを定義し (例: 、 など内LinearLayout) FrameLayoutプログラムでコードに追加します.java

tabs.xmlの構造があります。

構造図

上記の構造図からわかるように、xml コードには .xml にのみオブジェクト (TextView、RadioButton など) があり<RelativeLayout android:id="@+id/Network" </>ます。他の s で表示したいオブジェクトを追加してくださいRelativeLayout(つまり、電源、接続、およびオフライン)。

他の 3 つのすべてのオブジェクトを追加したら、コード内でタブに設定RelativeLayoutするコードを記述する必要があります。たとえば、次のコードは に設定されます。.java <RelativeLayout android:id="@+id/Networktab1

mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Network")
            .setContent(R.id.Network));

上記を繰り返し、必要に応じて 4 つのタブをすべて追加してください。NetworkR.id.Networkを他のタブ名 (例Powerと) に置き換えることができますR.id.Power

于 2013-03-12T07:22:43.570 に答える