2010-12-14 82 views
0

我有一些不同高度的图标,我的HTC Legend上的默认tabspec布局将图标放在顶部。看起来像内置布局的TabHost.TabSpec布局

我想通过为tabspec定义我自己的布局来对其进行居中,但经过多次实验后,我仍然无法使其看起来像内置布局。

所以我需要为我的tabspec布局内置填充&背景,任何人都知道他们被称为什么? -

+0

将样式设置为“@android:style/Widget.TabWidget”导致:android.content.res.Resources $ NotFoundException:来自可绘制资源ID的文件res/drawable-mdpi/title_bar_shadow.9.png#0x1030034 – 2010-12-14 15:54:53

回答

0

太多摆弄通过创建一个固定的高度和宽度可变图标的标签解决它:

private Drawable getTabIcon(byte chainID, Resources res) { 
    BitmapDrawable chainIcon = (BitmapDrawable) res.getDrawable(ChainDisplay.getIconID(chainID)); 

    int tabIconHeight; 
    switch(res.getDisplayMetrics().densityDpi) { 
     case DisplayMetrics.DENSITY_LOW: 
      tabIconHeight = 24; 
      break; 
     case DisplayMetrics.DENSITY_MEDIUM: 
      tabIconHeight = 32; 
      break; 
     case DisplayMetrics.DENSITY_HIGH: 
      tabIconHeight = 48; 
      break; 
     default: 
      tabIconHeight = 48; 
      break; 
    } 

    Bitmap tabIconBitmap = Bitmap.createBitmap(chainIcon.getIntrinsicWidth(), tabIconHeight, Bitmap.Config.ARGB_8888); 
    new Canvas(tabIconBitmap).drawBitmap(chainIcon.getBitmap(), 0, (tabIconHeight - chainIcon.getIntrinsicHeight())/2, null); 
    return new BitmapDrawable(tabIconBitmap); 
} 

做了一些与缩放和Paint.ANTI_ALIAS_FLAG实验,但它是丑陋的,所以图像裁剪被选中。