2011-08-09 44 views
3

我怎樣才能減少標籤高度和頂部的文本?減少標籤高度並對齊頂部的文字?

import android.app.TabActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.TabHost; 

public class MessagesTabs extends TabActivity{ 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.messages_tabs); 

     //Resources res = getResources(); // Resource object to get Drawables 
     TabHost tabHost = getTabHost(); // The activity TabHost 
     TabHost.TabSpec spec; // Resusable TabSpec for each tab 
     Intent intent; // Reusable Intent for each tab 

     // Create an Intent to launch an Activity for the tab (to be reused) 
     intent = new Intent().setClass(this, GetMessages.class); 

     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabHost.newTabSpec("inbox").setIndicator("Inbox") 
     .setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same for the other tabs 
     intent = new Intent().setClass(this, GetConversations.class); 
     spec = tabHost.newTabSpec("conversation").setIndicator("Conversation") 
     .setContent(intent); 
     tabHost.addTab(spec); 
     /* 
     intent = new Intent().setClass(this, SongsActivity.class); 
     spec = tabHost.newTabSpec("songs").setIndicator("Songs", 
          res.getDrawable(R.drawable.ic_tab_songs)) 
         .setContent(intent); 
     tabHost.addTab(spec);*/ 

     tabHost.setCurrentTab(0); 
    } 


} 

XMLFILE

<?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" 
     > 
     <TabWidget   
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      /> 

    </LinearLayout> 

</TabHost> 

回答

3

只是嘗試一下本作增加了標籤的高度:

tabHost.getTabWidget().getChildAt(index).getLayoutParams().height =(int) height; 

文本對齊試試這個在您的XML佈局:

android:gravity="top"android:layout_gravity="top"

+0

Thnka很多!!它的工作 – Harinder

0

您需要爲您的選項卡創建自定義佈局,並對其進行充氣並使用setIndicator

1

使用此代碼。它可能適合你:

for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) { 
    tabHost.getTabWidget().getChildAt(i).getLayoutParams().height /= 2; 
} 
相關問題