2014-06-23 115 views
0

我正在學習Android開發,我試圖在片段內製作一個標籤界面,底部的標籤。我見過很多關於如何使用RelativeLayout將標籤配置在底部的網頁(like this one),但我無法在屏幕上找到正確的東西。Android FragmentTabHost佈局定位

該標籤的FrameLayout正在採取所有的空間,爲選項卡界面,而且標籤不能被看到:

tabs not being shown

我使用的代碼是:

 <android.support.v13.app.FragmentTabHost 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@android:id/tabhost" 
      android:layout_marginRight="5dp" 
      android:layout_alignTop="@+id/ibRight" 
      android:layout_alignBottom="@+id/ibRight" 
      android:layout_toLeftOf="@+id/ibRight" 
      android:layout_alignLeft="@+id/ibTop"> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <TabWidget 
        android:id="@android:id/tabs" 
        android:layout_alignParentBottom="true" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" /> 

       <FrameLayout 
        android:id="@android:id/tabcontent" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" /> 
      </RelativeLayout> 
     </android.support.v13.app.FragmentTabHost> 

剛作爲一個快速測試,我調整了寬度和高度以固定(500dp和200dp),這就是我得到的結果:

Tab with tabs

所以這樣我可以看到所有的東西都在那裏,但是我不能讓它顯示正確,沒有使用固定的寬度和高度數字。而事實上,Android Studio有一個bug,它導致FragmentTabLayout呈現爲空引用使事情更難以發揮,因爲我無法實時測試選項。

我很感謝有人能幫助我,因爲我是Android新手,我不太清楚如何完成這項工作。

回答

-2

得到它用下面的代碼工作:

 <android.support.v13.app.FragmentTabHost 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@android:id/tabhost" 
      android:layout_marginRight="5dp" 
      android:layout_alignTop="@+id/ibBannerRight" 
      android:layout_alignBottom="@+id/ibBannerRight" 
      android:layout_toLeftOf="@+id/ibBannerRight" 
      android:layout_alignLeft="@+id/ibBannerTop"> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <TabWidget 
        android:id="@android:id/tabs" 
        android:layout_alignParentBottom="true" 
        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" 
        android:layout_above="@android:id/tabs"/> 
      </RelativeLayout> 
     </android.support.v13.app.FragmentTabHost> 

的祕訣是在android:layout_above="@android:id/tabs"

現在一切似乎很動聽:

enter image description here

enter image description here

+0

請把t上的選項卡他在Android中名列前茅。這不是iOS –

+2

確切地說,這不是iOS,這意味着我可以自由地按照自己喜歡的方式進行操作,不像Apple喜歡它,也不像Google喜歡它,但是我喜歡它。猜猜看,對於特定的應用程序,製表符必須放在最下面(我有充足的理由,因爲它是一個自助服務終端系統),這是免費的:) – mFeinstein

+1

在設計指南中免費是很好的! –