2010-03-08 84 views
7

我正在做tabactivity。如何在android中設置屏幕底部的標籤?

我想在tabcontent(framelayout)下面顯示我的tabwidget。

我通過設置tabwiget標籤屬性來完成它作爲

android:gravity="bottom" 

但不能FrameLayout裏與標籤一致。即標籤在屏幕底部顯示和重疊的FrameLayout

如何做到這一點?如果將一些高度值設置爲framelayout,則不會針對android的所有屏幕進行優化。我能做什麼?任何想法???

+0

請花幾秒鐘的搜索現有的問題。同樣的問題被問*昨天*:http://stackoverflow.com/questions/2395661/android-tabs-at-the-bottom – 2010-03-08 13:59:31

+0

我認爲克里斯托弗的觀點是,如果人們無法回答其他人的問題,他們可能也無法回答你的問題。換句話說,不需要再次提出這個問題,而是應該嘗試向其他地方尋找。 – 2010-03-08 15:17:47

+0

由於這個問題是重複的,我將簡單地鏈接到關於另一個問題的完整答案。 [http://stackoverflow.com/questions/2395661/android-tabs-at-the-bottom/2710404#2710404](http://stackoverflow.com/questions/2395661/android-tabs-at-the-bottom/ 2710404#) – stormin986 2010-04-25 23:44:02

回答

3

Android的救援示例!

http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

只是交換tabcontent和在res /佈局/ main.xml中標籤:

<LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp"> 
    <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp" />   
    <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 
+0

兩個認爲我必須告訴你。 1.它不工作,除非你爲你的tabwidget設置引力。 2.當framelayout內容的高度i大於屏幕高度時,tabwidget會從我們的屏幕失去其可見性。 請嘗試你的例子,讓我知道。 – Praveen 2010-03-10 08:23:51

0

檢查Tab-Activity這背後

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@android:id/tabhost"> 
<LinearLayout android:id="@+id/LinearLayout01" 
android:orientation="vertical" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent"> 

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

    <TabWidget 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:layout_gravity="bottom" 
android:id="@android:id/tabs"> 
</TabWidget> 
</FrameLayout> 

</LinearLayout> 

4

的基本概念如下

TabHost是一個標籤式窗口視圖的容器。 此對象包含兩個子項:用戶單擊以選擇特定選項卡的一組選項卡標籤,以及顯示該頁面內容的FrameLayout對象。

單個元素通常使用此容器對象進行控制,而不是在子元素本身上設置值。

TabWidget顯示錶示父級選項卡集合中每個頁面的選項卡標籤列表。這個小部件的容器對象是TabHost。 當用戶選擇一個選項卡時,該對象向容器TabHost發送一條消息,告訴切換顯示頁面。容器TabHost用於添加標籤,添加回調處理程序並管理回調。

所以調整佈局如下 -

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

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

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
    </FrameLayout> 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="-3dip" 
     android:layout_weight="0" > 
    </TabWidget> 
    </LinearLayout> 

    </TabHost> 
0

這是底部的標籤代碼

<TabWidget 
android:layout_width="fill_parent" 
android:layout_height="60dp" 
android:layout_gravity="bottom" 
android:background="#0000" 
android:id="@android:id/tabs" 
/> 



    "android:layout_gravity="bottom"