2011-08-30 91 views
1

我正在使用一個標籤小部件來模擬iPhone中的菜單。這裏是我的屏幕的圖片enter image description here如何讓我的標籤更小?

正如你可以看到單詞不適合在個別框。我怎樣才能使每個部件的文字大小更小?還有沒有辦法縮小標籤內的圖片,使他們看起來不那麼擠塞?到目前爲止,圖標都「符合尺寸」,因此它儘可能佔用儘可能多的空間。

感謝您的幫助,請參閱下面的我的代碼上的標籤

@Override 
public void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.tab_layout); 
    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 

    intent = new Intent().setClass(this, ImTracking.class); 
    spec = tabHost 
      .newTabSpec("imtracking") 
      .setIndicator("I\'m Tracking", 
        res.getDrawable(R.drawable.mapbutton)) 
      .setContent(intent); 
    tabHost.addTab(spec); 
    intent = new Intent().setClass(this, TrackingMe.class); 
    spec = tabHost 
      .newTabSpec("trackingme") 
      .setIndicator("Tracking Me", 
        res.getDrawable(R.drawable.friends)).setContent(intent); 
    tabHost.addTab(spec); 
    intent = new Intent().setClass(this, Settings.class); 
    spec = tabHost 
      .newTabSpec("settings") 
      .setIndicator("Settings", 
        res.getDrawable(R.drawable.settingsicon)) 
      .setContent(intent); 
    tabHost.addTab(spec); 
    intent = new Intent().setClass(this, Review.class); 
    spec = tabHost.newTabSpec("review") 
      .setIndicator("Review", res.getDrawable(R.drawable.like)) 
      .setContent(intent); 
    tabHost.addTab(spec); 
    intent = new Intent().setClass(this, help.class); 
    spec = tabHost.newTabSpec("help") 
      .setIndicator("Help", res.getDrawable(R.drawable.help)) 
      .setContent(intent); 
    tabHost.addTab(spec); 
    tabHost.setCurrentTab(0); 

編輯 這裏是XML tab_layout.xml

<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="0dp"> 

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

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

    </LinearLayout> 

</TabHost> 

tab.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" 
android:orientation="vertical" android:padding="0dp"> 
<ImageView android:id="@+id/tab_icon" android:layout_width="30dp" 
    android:layout_height="30dp" android:scaleType="fitCenter" /> 
<TextView android:id="@+id/tab_text" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:singleLine="true" 
    android:textStyle="bold" android:gravity="center_horizontal" 
    android:textSize="10sp" android:padding="3dip" android:ellipsize="marquee" 
    /> 
</LinearLayout> 
+0

您可以添加相關的XML代碼? – Vinay

回答

3

你可以使用TabWidget的實現,它的自定義選項卡!您可以輕鬆編輯與這些自定義選項卡關聯的佈局和視圖。

被警告,選中/未選中時,這些選項卡不會使用系統背景作爲選項卡顏色,並使用您在下圖中看到的灰色外觀。

http://code.google.com/p/android-custom-tabs/

Android custom tabs

+0

在教程中,沒有提到添加自定義圖像。我相信問題出在setIndicator方法,你認爲你可以幫助修復我的代碼,以便它能正常工作嗎?謝謝 –

+0

查看該選項卡的佈局文件。您可以在那裏設置自定義圖像,然後設置圖像源位置。 –

+0

然後增加填充值,以便圖像不會縮放到邊緣。 – StackOverflowed