Monodroid 选项卡视图

发布于 2024-12-05 19:44:48 字数 1358 浏览 0 评论 0原文

实现 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 技术交流群。

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

发布评论

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

评论(1

宫墨修音 2024-12-12 19:44:48

我猜这是因为第三个选项卡没有选项卡可供访问(因为我们没有创建 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" />

然后当显示选项卡时,文本视图再次可见。

希望这有帮助,

克里斯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;

<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" />

and then when the tab is displayed, the text view is made visible again.

Hope this helps,

ChrisNTR

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