需要 Android 选项卡布局示例

发布于 2024-12-01 22:57:53 字数 278 浏览 4 评论 0原文

我正在寻找一个示例,例如标准的“选项卡布局”教程,该教程为每个选项卡使用两个活动,并为每个选项卡使用专用的 xml 布局文件。

任何人都可以帮忙。我发现的所有示例都只是使用以下布局。

TextView textview = new TextView(this);
textview.setText("This is the Artists tab");
setContentView(textview);

使用活动的原因是,对于其中一个选项卡,我想强制横向。

I'm looking for an example, like the standard "Tab Layout" tutorial that uses BOTH activities for each tab and a dedicated xml layout file for each tab.

Can anyone help. All the examples I've found simply use the following for the layout

TextView textview = new TextView(this);
textview.setText("This is the Artists tab");
setContentView(textview);

The reason for using activities is that for one of the tabs I want to force a landscape orientation.

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

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

发布评论

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

评论(3

回梦 2024-12-08 22:57:53

在这里试试:

http://www.androidpeople.com/android-tabhost-tutorial-第 1 部分

如果您需要任何帮助,请告诉我,因为我的应用程序中有一个完全定制的 TabHost。

谢谢

Try here:

http://www.androidpeople.com/android-tabhost-tutorial-part-1

If you need any help with this let me know because I have a fully customized TabHost in my APP's.

Thanks

居里长安 2024-12-08 22:57:53

选项卡布局教程展示了如何为每个选项卡使用单独的活动内容。只需将其与以下代码片段结合起来即可:

TabHost.TabSpec spec = tabHost.newTabSpec("layout tab")
   .setIndicator("Layout based tab")
   .setContent(new TabHost.TabContentFactory(){
      public View createTabContent (String tag) {
         return getLayoutInflater().inflate(R.layout.layout_tab, null);
      }
});

tabHost.addTab(spec);

Intent intent = new Intent().setClass(this, MyActivity.class);
spec = tabHost.newTabSpec("activity tab")
   .setIndicator("Activity based tab")
   .setContent(intent);

tabHost.addTab(spec);

The Tab Layout Tutorial shows how to use separate activities for each tab's content. Just combine it with the following code snippet:

TabHost.TabSpec spec = tabHost.newTabSpec("layout tab")
   .setIndicator("Layout based tab")
   .setContent(new TabHost.TabContentFactory(){
      public View createTabContent (String tag) {
         return getLayoutInflater().inflate(R.layout.layout_tab, null);
      }
});

tabHost.addTab(spec);

Intent intent = new Intent().setClass(this, MyActivity.class);
spec = tabHost.newTabSpec("activity tab")
   .setIndicator("Activity based tab")
   .setContent(intent);

tabHost.addTab(spec);
晨曦慕雪 2024-12-08 22:57:53

寻找通用TabHost 样式适用于 Android、HTC Sense、Samsung 等皮肤

除了您的 ActivityGroup 中的样式之外:

public class YourActivityGroup extends ActivityGroup {

private List<View> viewCache;

public void replaceView(View view) {
    if (viewCache == null) {
        viewCache = new ArrayList<View>();
    }
    viewCache.add(view);
    setContentView(view);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Replace the view of this ActivityGroup
    replaceView(startYourActivity());
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // handling rotation
    resetCache();

    // reset the ui
    replaceView(startYourActivity());
}

private View startYourActivity() {
    // Start the root activity withing the group and get its view
    return getLocalActivityManager().startActivity(YourActivity.class.getSimpleName(),
            new Intent(this, YourActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
}

/**
 * Clears the View cache.
 */
public void resetCache() {
    viewCache = new ArrayList<View>();
}

@Override
public void onBackPressed() {
    this.back();
}

}

休息很容易。^^

Looking for a universal TabHost style that will work on Android, HTC Sense, Samsung, etc. skins

In addition to that in your ActivityGroup:

public class YourActivityGroup extends ActivityGroup {

private List<View> viewCache;

public void replaceView(View view) {
    if (viewCache == null) {
        viewCache = new ArrayList<View>();
    }
    viewCache.add(view);
    setContentView(view);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Replace the view of this ActivityGroup
    replaceView(startYourActivity());
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // handling rotation
    resetCache();

    // reset the ui
    replaceView(startYourActivity());
}

private View startYourActivity() {
    // Start the root activity withing the group and get its view
    return getLocalActivityManager().startActivity(YourActivity.class.getSimpleName(),
            new Intent(this, YourActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
}

/**
 * Clears the View cache.
 */
public void resetCache() {
    viewCache = new ArrayList<View>();
}

@Override
public void onBackPressed() {
    this.back();
}

}

Rest is easy.^^

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