2016-08-03 55 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已被棄用,所以我必須找到另一種實現製表符的方式,例如頁面滑塊或滑動製表符。

相關問題