2010-03-07 93 views
146

我已經看到一些關於此的喋喋不休,但沒有確定。 有沒有辦法將TabWidget中的標籤放到屏幕的底部? 如果是這樣,怎麼樣?Android:底部的標籤

我試過以下,但沒有奏效:

一)設置以下的FrameLayout
B中的tabwidget)設置tabwidget的重力 「底」

謝謝! llappall

+10

請定義「沒有工作」。 – CommonsWare 2010-03-07 13:54:43

+3

[看這裏](http://stackoverflow.com/a/6992662/593709)如果你想iPhone像標籤主機。 – 2012-03-21 11:09:25

+0

我從下面的網站使用一個。 它的工作[http://kpbird.blogspot.com/2011/05/androidbottom-tabbar-control.html](http://kpbird.blogspot.com/2011/05/androidbottom-tabbar-control.html) – Juliousraj 2011-09-07 05:27:57

回答

1

這可能不是您正在尋找的東西(將標籤發送到屏幕底部並不是一個「簡單」的解決方案),但仍然是我想標記給您的一個有趣的替代解決方案:

ScrollableTabHost旨在表現得像TabHost,但有一個附加的滾動視圖,以適應更多的項目......

可能挖掘到這個開源項目,你會發現一個回答你的問題。如果我看到更簡單的東西,我會回到你身邊。

1

是,請參閱:link,但他使用了XML的佈局,不活動,以創造新的標籤,所以把他的XML代碼(集paddingTop爲FrameLayout裏 - 0像素),然後寫代碼:

public class SomeActivity extends ActivityGroup { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host); 

    tab_host.setup(this.getLocalActivityManager()); 

    TabSpec ts1 = tab_host.newTabSpec("TAB_DATE"); 
    ts1.setIndicator("tab1"); 
    ts1.setContent(new Intent(this, Registration.class)); 
    tab_host.addTab(ts1); 

    TabSpec ts2 = tab_host.newTabSpec("TAB_GEO"); 
    ts2.setIndicator("tab2"); 
    ts2.setContent(new Intent(this, Login.class)); 
    tab_host.addTab(ts2); 

    TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT"); 
    ts3.setIndicator("tab3"); 
    ts3.setContent(new Intent(this, Registration.class)); 
    tab_host.addTab(ts3); 

    tab_host.setCurrentTab(0);  


} 

}

269

下面是最簡單,最健壯,最具擴展性的解決方案,讓屏幕底部顯示標籤。

  1. 在你垂直的LinearLayout,放的FrameLayout的TabWidget
  2. 設置layout_height以上wrap_content雙方的FrameLayout和TabWidget
  3. 設置的FrameLayout的android:layout_weight="1"
  4. 集TabWidget的android:layout_weight="0"(0爲默認值,但強調,可讀性等)
  5. Set TabWidget's android:layout_marginBottom="-4dp"(去除底部分隔線)

全碼:

<?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: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="wrap_content" 
      android:padding="5dp" 
      android:layout_weight="1"/> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" 
      android:layout_marginBottom="-4dp"/> 

    </LinearLayout> 

</TabHost> 
+3

分隔線實際上是硬編碼的。我試圖改變用於標籤的可繪製並找到它。總是無賴。 – 2010-04-26 15:58:21

+0

你確實發現它在Widget中的編碼位置,並且沒有界面可以改變它?令人驚訝和令人失望。所以目前唯一的解決方案是在其上方手動繪製分隔線,並將標籤下方的線保留下來...... – stormin986 2010-04-26 22:10:08

+0

我的方法是將標籤簡單重新對齊到底部。對於具有此功能和其他功能的自定義TabWidget,看起來像這個人制作了一個支持標籤垂直對齊的標籤,還有一些其他自定義選項,例如標籤背景/圖標。 – stormin986 2010-04-26 22:20:26

37

試試吧;) 只是看的FrameLayout的內容(@ ID/tabcontent),因爲我不知道它將如何在滾動的情況下處理...在我的情況下,它的作品,因爲我用ListView作爲我的標籤的內容。 :) 希望它有幫助。

<?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"> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <FrameLayout android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_alignParentTop="true" 
      android:layout_above="@android:id/tabs" /> 
    <TabWidget android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" /> 
    </RelativeLayout> 
</TabHost> 
+4

+1但您是否注意到屏幕上方的黑色/灰色條?你是如何刪除它的? – 2010-11-03 14:32:22

+0

我正在使用它將選項卡小部件發佈到窗體的左側。 – 2012-05-16 03:19:42

1

我試圖將它們放在屏幕底部時遇到了與安卓標籤相同的問題。我的方案是不使用佈局文件並在代碼中創建選項卡,我還希望從每個選項卡觸發活動,使用其他方法似乎有點太複雜,因此,下面是用於解決問題的示例代碼:

adding-tabs-in-android-and-placing-them

+1

不在這裏發佈代碼會使您的答案不完整。 – BryanH 2011-07-05 01:04:33

3

對於所有那些嘗試刪除tabWidget分隔線的人來說,這裏是一個示例項目(及其相應的教程),這對於定製選項卡非常適用,因此可以在選項卡處於底部時刪除問題。 Eclipse項目:android-custom-tabs; 原文解釋:blog; 希望這有助於。

3

不知道是否會爲Android的所有版本(特別是那些定製UI的東西)工作,但我可以通過添加

android:layout_marginBottom="-3dp" 

到TabWidget XML,除去底部的灰色欄。 ..

3

有兩種顯示選項卡活動底部的選項卡的方法。

  1. 使用相對佈局
  2. 使用Layout_weight屬性

請檢查link for more details

+1

非常容易和重點!謝謝! – MaKo 2012-05-28 04:42:19

10

有一種方法可以刪除該行。

1)按照本教程: android-tabs-with-fragments

2)然後應用RelativeLayout的更改,Leaudro上面所建議的(應用的佈局道具所有FrameLayouts)。

您還可以將ImageView添加到項目#1中的tab.xml中,並獲得非常類似於標籤的iPhone。

下面是我正在工作的一個截圖。我還有一些工作要做,主要是爲圖標選擇一個選擇器,並確保水平分佈均勻,但你明白了。 就我而言,我使用的是片段,但是相同的主體應該適用於標準的標籤視圖。

enter image description here

+0

自從您發佈這條消息以來,它已經有一段時間了,但您的鏈接現在說__歡迎使用nginx!__,頁面上沒有任何其他內容。 – DroidDev 2014-09-09 12:47:04

+0

這不是我的網站,sop我不能控制它。 經過這段時間,系統已經發生了很大的變化,你可能不應該爲你的Android用戶實現這種接口,他們會希望事情現在有點不同。 – 2014-09-09 16:00:23

3
<?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: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="0dip" 
      android:layout_weight="1" /> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" 
      android:background="#252a31" 
      android:tabStripEnabled="false" > 
     </TabWidget> 
    </LinearLayout> 

</TabHost>