2016-08-03 57 views
0

所以我一直坚持一会儿,现在试图在我的项目中实现一对选项卡。我已经阅读了很多关于如何做到这一点的内容,但我不确定它为什么不起作用。有谁可以告诉我我做错了什么?这里是我的.csAndroid选项卡无法正常工作C#

public class TabActivity1 : Activity 
{ 
    protected override void OnCreate(Bundle savedInstanceState) 
    { 
     base.OnCreate(savedInstanceState); 
     TextView textview = new TextView(this); 
     textview.Text = "Tab 1"; 
     SetContentView(textview); 
    } 
} 

public class TabActivity2 : Activity 
{ 
    protected override void OnCreate(Bundle savedInstanceState) 
    { 
     base.OnCreate(savedInstanceState); 
     TextView textview = new TextView(this); 
     textview.Text = "Tab 2"; 
     SetContentView(textview); 
    } 
} 


public class MainActivity : Activity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 
     SetContentView(Resource.Layout.Main); 

     TabHost tab_host = FindViewById<TabHost>(Resource.Id.tabHost); 
     TabHost.TabSpec spec; 
     Intent intent; 

     intent = new Intent(this, typeof(TabActivity1)); 
     intent.AddFlags(ActivityFlags.NewTask); 
     spec = tab_host.NewTabSpec("Tab 1"); 
     spec.SetIndicator("tab1"); 
     spec.SetContent(intent); 
     tab_host.AddTab(spec); 

     intent = new Intent(this, typeof(TabActivity2)); 
     intent.AddFlags(ActivityFlags.NewTask); 
     spec = tab_host.NewTabSpec("Tab 2"); 
     spec.SetIndicator("tab2"); 
     spec.SetContent(intent); 
     tab_host.AddTab(spec); 
    } 
} 

这里的.axml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:minWidth="25px" 
android:minHeight="25px"> 
<TabHost 
    android:minWidth="25px" 
    android:minHeight="25px" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/tabHost"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:id="@+id/linearLayout1"> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 
</TabHost> 
</LinearLayout> 

Here的是什么应用程序输出。

我真的很感激任何帮助,我可以得到,谢谢!

+0

那么,预期的输出是什么?仅仅通过查看代码来猜测想要的结果是相当烦人的。 – hankide

+0

我希望有两个选项卡,分别是选项卡1和选项卡2,并且每个选项卡都有一个文本框,用于说明选项卡1中的选项卡1和选项卡2中的选项卡2。您认为我可以做什么来实现这一目标? –

回答

0

因此,经过一番研究后,我发现Activity TabActivity已被弃用,所以我必须找到另一种实现制表符的方式,例如页面滑块或滑动制表符。

相关问题