如何删除/替换android中的tab活动?

时间:2011-11-22 16:45:05

标签: android android-activity tabs

我已经实现了4个标签,每个标签都有与之关联的活动。是否建议删除/替换这些活动以获得更好的应用程序性能?如果是,那该怎么办?

1 个答案:

答案 0 :(得分:0)

我真的怀疑有3个标签而不是4个标签会明显改变性能。您需要拥有适合您应用的标签数量。在我的应用程序中,我需要4个标签,因为如果我有3个,那么使用能力会很差,导航会很困惑。
如果你想要5个以上的标签,那么我建议不再使用tabwidget,然后实现你自己的自定义布局(可能是一个水平滚动视图),就像在WeatherBug中实现的一样。然后在该自定义布局上,在每个按钮或imageView或自定义布局中的任何内容上,您可以在onClick中为视图调用setCurrentTab

我有4个这样的标签:

intent = new Intent().setClass(this, ActivityTabOther.class);
        spec = tabHost.newTabSpec("other").setIndicator("General",
                          res.getDrawable(R.drawable.other))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, ActivityTabLocate.class);
        spec = tabHost.newTabSpec("locate").setIndicator("Locate",
                          res.getDrawable(R.drawable.locate))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, ActivityTabSecure.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("secure").setIndicator("Secure",
                          res.getDrawable(R.drawable.secure))
                      .setContent(intent);
        tabHost.addTab(spec);
        //If you want to remove a tab, delete everything from here down, and that's minus one tab.
        intent = new Intent().setClass(this, ActivityTabFriends.class);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("friends").setIndicator("Friends",
                          res.getDrawable(R.drawable.findabuddy))
                      .setContent(intent);
        tabHost.addTab(spec);