5

AndroidでTabHostを作成するためのサンプルコードが必要です。誰でも私を助けることができます。

4

4 に答える 4

7

Android デベロッパー サイトには、 と を使用して Android でタブを作成するための完全に機能する優れたコード サンプルがTabWidgetありTabHostます。

Hello, TabWidget をチェックしてください。

于 2009-06-05T06:37:55.780 に答える
2

スコアの表示に関してタブホスト関連のコードを実行しました

    TabHost host = getTabHost();
    host.setup ();

    TabSpec allScoresTab = host.newTabSpec("allTab");
    allScoresTab.setIndicator(getResources().getString(R.string.all_scores), getResources().getDrawable(android.R.drawable.star_on));
    allScoresTab.setContent(R.id.ScrollViewAllScores);
    host.addTab(allScoresTab);

    TabSpec friendScoresTab = host.newTabSpec("friendsTab");
    friendScoresTab.setIndicator(getResources().getString(R.string.friends_scores), getResources().getDrawable(android.R.drawable.star_on));
    friendScoresTab.setContent(R.id.ScrollViewFriendScores);
    host.addTab(friendScoresTab);

    host.setCurrentTabByTag("allTab");

私のxmlには次が含まれています:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bkgrnd">
    <RelativeLayout
        android:id="@+id/RelativeLayout01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ImageView_Header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/quizicon"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true">
        </ImageView>
        <TextView
            android:id="@+id/TextView01"
            android:layout_height="wrap_content"
            android:text="@string/scores"
            android:textSize="@dimen/screen_title_size"
            android:shadowDx="0"
            android:shadowDy="0"
            android:shadowRadius="10"
            android:layout_width="wrap_content"
            android:layout_gravity="fill_horizontal|center"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:shadowColor="@android:color/white"
            android:textColor="@color/title_color">
        </TextView>
        <ImageView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ImageView_Header2"
            android:layout_height="wrap_content"
            android:src="@drawable/quizicon"
            android:layout_gravity="right|center_vertical"
            android:layout_width="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true">
        </ImageView>
    </RelativeLayout>
   <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:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <ScrollView android:id="@+id/ScrollViewAllScores" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="vertical">
  <TableLayout android:id="@+id/TableLayout_AllScores" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*" /> 
  </ScrollView>
- <ScrollView android:id="@+id/ScrollViewFriendScores" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="vertical">
  <TableLayout android:id="@+id/TableLayout_FriendScores" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*" /> 
  </ScrollView>
        </FrameLayout>
    </LinearLayout>
</TabHost>
</LinearLayout>
于 2010-12-04T18:22:33.877 に答える
0

activity_main.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="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

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

        <HorizontalScrollView
            android:id="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none"
            android:layout_alignParentBottom="true" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/tabs_bg" />
        </HorizontalScrollView>
    </RelativeLayout>

</TabHost>

そしてJavaコードは

TabHost tabHost = getTabHost();

        TabSpec spec;

        Intent intent;

        //Home Tab
        View view1 = LayoutInflater.from(MainActivity.this).inflate(R.layout.home, null);

        intent = new Intent(MainActivity.this, Firstclass.class);

        spec = tabHost.newTabSpec("HOME").setIndicator(view1)
                .setContent(intent);

        tabHost.addTab(spec);

        //Calendar Tab
        View view2 = LayoutInflater.from(MainActivity.this).inflate(R.layout.calendar_tab, null);

        intent = new Intent(MainActivity.this, Calendar.class);

        spec = tabHost.newTabSpec("CALENDAR").setIndicator(view2)
                .setContent(intent);

        tabHost.addTab(spec);
于 2014-04-10T13:13:45.753 に答える