如何删除/替换Android中的选项卡活动?

发布于 2024-12-17 19:55:19 字数 74 浏览 0 评论 0原文

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

I have implemented 4 tabs, each having an activity assosiated with it. Is it advisable to remove/replace those activities for better performance of app? If yes then how to do it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风月客 2024-12-24 19:55:19

我真的怀疑使用 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);

I really doubt that having 3 tabs instead of 4 will noticeably change performance. You need to have as many tabs as suits your app. In my app, I need 4 tabs because if I had 3, then the use ability would be bad, and it would be confusing to navigate.
If you want 5+ tabs, then I'd recommend doing away with the tabwidget and then implement your own custom layout (possibly a horiziontal scrollview) as is implemented in WeatherBug. Then on that custom layout, on each button or imageView or whatever is in your custom layout, you would call setCurrentTab in an onClick for the views.

And I have 4 tabs like this:

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文