【问题标题】:Android tab layout example required需要 Android 选项卡布局示例
【发布时间】:2011-09-01 14:37:52
【问题描述】:

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

谁能帮忙。我发现的所有示例都简单地使用以下布局

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

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

【问题讨论】:

标签: android layout tabs


【解决方案1】:

在这里试试:

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

如果您需要任何帮助,请告诉我,因为我的 APP 中有一个完全自定义的 TabHost。

谢谢

【讨论】:

    【解决方案2】:

    Tab Layout Tutorial 展示了如何为每个选项卡的内容使用单独的活动。只需将其与以下代码 sn-p 结合即可:

    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);
    

    【讨论】:

      【解决方案3】:

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

      除了你的 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();
      }
      
      }
      

      休息很容易。^^

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多