1

iPhoneでUITabBarControllerと同じようにやりたい、4つのクラスがあり、1つのタブでそれらを操作したい

最初のタブをクリックすると、最初のクラスは2番目のタブをクリックすると表示され、2番目のクラスは3番目のタブをクリックすると表示され、3番目のクラスは4番目のタブをクリックすると表示され、4番目のクラスは表示されます

そのような条件で操作するための最良かつ簡単な方法は何ですか、私はAndroidの開発に不慣れであり、これはあなたが質問で明確でない場合は私の最初のアプリです、もう一度尋ねるかもしれません...

4

2 に答える 2

0

android devサイトには、まさにあなたが探している例があります。http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

コード例があります。タブレイアウトのxmlファイルを作成し、main.xmlを編集してから、Javaコードで、タブごとに次のようなものを作成する必要があります。

intent = new Intent().setClass(this, AlbumsActivity.class);
spec = tabHost.newTabSpec("albums").setIndicator("Albums",
       res.getDrawable(R.drawable.ic_tab_albums))
      .setContent(intent);
tabHost.addTab(spec);
于 2011-07-01T11:41:23.953 に答える
0

これは Android でタブ バーを実装するための Java コードです。

           tabHost = getTabHost(); // The activity TabHost
    tabHost.setOnTabChangedListener(this);
    Resources res = getResources(); // Resource object to get Drawables
    tabHost = getTabHost(); // The activity TabHost
    TabHost.TabSpec spec; // Reusable TabSpec for each tab

    TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
    TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
    TabSpec thirdTabSpec = tabHost.newTabSpec("tid3");
    TabSpec fourthTabSpec = tabHost.newTabSpec("tid4");
    TabSpec fifthTabSpec = tabHost.newTabSpec("tid5");

    viewCache[0] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
    viewCache[1] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
    viewCache[2] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
    viewCache[3] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
    viewCache[4] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);

    firstTabSpec.setIndicator(viewCache[0]);
    secondTabSpec.setIndicator(viewCache[1]);
    thirdTabSpec.setIndicator(viewCache[2]);
    fourthTabSpec.setIndicator(viewCache[3]);
    fifthTabSpec.setIndicator(viewCache[4]);

    firstTabSpec.setContent(new Intent(this, HomeTabActivityGroup.class));
    secondTabSpec
            .setContent(new Intent(this,   ProfileTabActivityGroup.class));
    thirdTabSpec.setContent(new Intent(this,
            NotificationTabActivityGroup.class));
    fourthTabSpec.setContent(new Intent(this,
            FavoritesTabActivityGroup.class));
    fifthTabSpec
            .setContent(new Intent(this, MoreTabActivityGroupNew.class));

    tabHost.addTab(firstTabSpec);
    tabHost.addTab(secondTabSpec);
    tabHost.addTab(thirdTabSpec);
    tabHost.addTab(fourthTabSpec);
    tabHost.addTab(fifthTabSpec);

// * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * * これは Tab の xml coed ですバー

 <?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: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_alignParentBottom="true" 
        android:layout_height="wrap_content" 
        tabStripEnabled = "false"/>
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_alignParentTop="true"
        android:layout_above="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
</RelativeLayout>

// * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * * これは Tab1 の xml coed ですタブ レイアウト用の .xml

   <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout android:id="@+id/LinearLayout01" 
android:layout_width="wrap_content" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center">
  <ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content"
        android:layout_height="50dip"></ImageView>
    </LinearLayout>
于 2011-07-01T12:58:24.190 に答える