2013-04-23 97 views
-2

我正在學習Android開發。目前,我試圖獲得基本的標籤頁面設置。在試圖做到這一點,我創建了以下axml:Android中的基本選項卡安裝無法正常工作

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:background="#fff" 
    android:layout_height="fill_parent"> 
    <RelativeLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:background="#2D2D2D" 
    android:layout_height="50dip" 
    android:minHeight="50dip"> 
     <LinearLayout 
     android:orientation="horizontal" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_centerHorizontal="true" 
     android:gravity="center" 
     android:id="@+id/linearLayout1"> 
    <TextView 
      android:text="@string/my" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/textView1" 
      android:layout_marginRight="0.0dp" 
      android:textColor="#ffefc6" 
      android:textSize="22dip" 
      android:editable="false" 
      android:focusable="false" /> 
    <TextView 
      android:text="@string/app" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/textView2" 
      android:textColor="#FFFFFF" 
      android:textSize="22dip" 
      android:editable="false" 
      android:focusable="false" /> 
     </LinearLayout> 
    </RelativeLayout> 

    <TabHost android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/tabHost"> 
    <RelativeLayout android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="3dp"> 
     <TabWidget android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
    android:id="@android:id/tabs" 
    android:layout_alignParentBottom="true" /> 

     <FrameLayout android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@android:id/tabcontent" 
     android:layout_alignParentTop="true"> 

      <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/tab1" 
     android:orientation="vertical"> 
      <TextView android:layout_width="fill_parent" 
      android:layout_height="100px" 
      android:text="This is tab1" 
      android:id="@+id/txt1"/> 
     </LinearLayout> 

     <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/tab2" 
     android:orientation="vertical"> 

     <TextView android:layout_width="fill_parent" 
      android:layout_height="100px" 
      android:text="This is tab2" 
      android:id="@+id/txt2"/> 
      </LinearLayout> 

     <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/tab3" 
     android:orientation="vertical"> 
      <TextView android:layout_width="fill_parent" 
      android:layout_height="100px" 
      android:text="This is tab3" 
      android:id="@+id/txt3"/> 
     </LinearLayout> 
    </FrameLayout> 
    </RelativeLayout> 
    </TabHost> 
</LinearLayout> 

當我試圖運行加載此佈局的活動,我收到一個錯誤,指出:「應用程序已意外停止,請重再次。」。這段代碼有什麼問題?它必須是簡單的。此刻我一直在盯着它5個小時。現在我覺得我太接近問題了。任何幫助深表感謝。

+1

後的logcat和UR java代碼 – Senthil 2013-04-23 13:47:21

回答

0

我不知道什麼不對的,但你也可以通過編碼像嘗試,

TabHost tabHost = getTabHost(); 

TabSpec Spec1 = tabHost.newTabSpec("Tab 1"); 
Spec1.setIndicator("Name of Tab 1"); 
Intent IntentTab1 = new Intent(this, tab1.class); 
Spec1.setContent(IntentTab1); 

TabSpec Spec2 = tabHost.newTabSpec("Tab 2"); 
Spec2.setIndicator("Name of Tab 2"); 
Intent IntentTab2 = new Intent(this, tab2.class); 
Spec2.setContent(IntentTab2); 


TabSpec Spec3 = tabHost.newTabSpec("Tab 3"); 
Spec3.setIndicator("Name of Tab 3"); 
Intent IntentTab3 = new Intent(this, tab3.class); 
Spec3.setContent(IntentTab3); 


tabHost.addTab(Spec1); 
tabHost.addTab(Spec2); 
tabHost.addTab(Spec3); 
相關問題