2011-09-22 49 views
0

实施Tabs Widget Sample后,我试着只改变到第二个选项卡MonoDroid的标签查看

protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     // Set our view from the "main" layout resource 
     SetContentView(Resource.Layout.Main); 

     TabHost.TabSpec spec; 

     spec = TabHost.NewTabSpec("tab_test1").SetIndicator("TAB 1").SetContent(Resource.Id.textview1); 
     TabHost.AddTab(spec); 

     spec = TabHost.NewTabSpec("tab_test2").SetIndicator("TAB 2").SetContent(Resource.Id.textview2); 
     TabHost.AddTab(spec); 

     //spec = TabHost.NewTabSpec("tab_test3").SetIndicator("TAB 3").SetContent(Resource.Id.widget0); 
     //TabHost.AddTab(spec); 

     TabHost.TabChanged += new EventHandler<Android.Widget.TabHost.TabChangeEventArgs>(TabHost_TabChanged); 

     TabHost.CurrentTab = 0; 
    } 

    void TabHost_TabChanged(object sender, TabHost.TabChangeEventArgs e) 
    { 
     if (TabHost.TabWidget.TabCount < 3) 
     { 
      TabHost.TabSpec spec; 

      spec = TabHost.NewTabSpec("tab_test3").SetIndicator("TAB 3").SetContent(Resource.Id.widget0); 
      TabHost.AddTab(spec); 
     } 
    } 

的问题后,用它玩,并添加第三个选项卡是我看到的第一个第三视图叠加-ED即使第三个标签仅在点击第二个标签后才出现,在点击标签之前查看。这是怎么回事?

回答

2

我猜这是因为第三个选项卡没有选项卡(因为我们不创建TabSpec),所以它只是直接在屏幕上显示它。

您可以设置您希望显示的内容,当第三个标签在下面的示例中显示为不可见时可见;

<TextView 
    android:visibility="invisible" 
    android:id="@+id/textview3" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:text="this is a third tab" /> 

然后当显示标签时,文本视图再次可见。

希望这有助于

ChrisNTR

+0

是的,做的工作。谢谢克里斯。 – Shy