2011-08-30 90 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