1

まずActivity、タブ ナビゲーション タイプを使用して生成された を使用しました。Tabでコントロールを自動的に生成するために使用しましたActivity。それは最新のADTにあります。私は思う:(、、私の質問は、内容にFragments他のものをどのように使用するかですActivityTab

Activity第二に、コンテンツ内に別のものを配置する他の方法はありTabますか?

Tab3 つの異なる を含む 3 つの を計画しており、それぞれにコンテンツごとActivityに 1 つ含まれていますActivitytab

私はアイデアとソースを使い果たしました:( :( ... Android開発の初心者なので、優しくしてください。:)

4

1 に答える 1

1

タブ.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">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
         >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_marginTop="60dp"/>
       <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp"/>
    </RelativeLayout>

</TabHost>

activity.java ファイルに以下のコードを追加します。

android.app.TabActivityの代わりにアクティビティを拡張しますActivity

TabHost tabHost=getTabHost();
    TabHost.TabSpec spec;
    Intent intent;

    intent=new Intent().setClass(YourActivity.this, NewActivity.class);
    spec=tabHost.newTabSpec("tab1").setIndicator("imageId").setContent(intent);
    tabHost.addTab(spec);

    intent=new Intent().setClass(YourActivity.this, New1Activity.class);
    spec=tabHost.newTabSpec("tab2").setIndicator("imageId").setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);

同様に、アクティビティにタブをいくつでも追加できます。

于 2012-07-23T11:19:11.983 に答える