Monodroid 选项卡视图
实现 Tabs Widget Sample 后,我尝试使用它并仅在之后添加第三个选项卡更改到第二个选项卡
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);
}
}
问题是,在单击选项卡之前,我在第一个视图上看到了第三个视图叠加,即使第三个选项卡仅在单击第二个选项卡后才出现。这是怎么回事?
After implementing the Tabs Widget Sample I tried to play with it and add the third tab only after changing to the second tab
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);
}
}
The problem is that I see the 3rd view overlay-ed on the first view before clicking the tabs, even though the 3rd tab appears only after clicking the 2nd tab. What's going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜这是因为第三个选项卡没有选项卡可供访问(因为我们没有创建 TabSpec),所以它只是直接将其显示在屏幕上。
您可以设置第三个选项卡可见或不可见时要显示的内容,如下例所示;
然后当显示选项卡时,文本视图再次可见。
希望这有帮助,
克里斯NTR
I'm guessing it's because the Third tab doesn't have tab to go to (since we don't create a TabSpec) so it just displays it directly on the screen.
You could set the content you want to display when the third tab is visible to invisible shown in the example below;
and then when the tab is displayed, the text view is made visible again.
Hope this helps,
ChrisNTR