Android TabHost.TabSpec布局,看起来像内置布局

Android TabHost.TabSpec布局,看起来像内置布局,android,layout,android-tabhost,Android,Layout,Android Tabhost,我有一些不同高度的图标,HTC Legend上的默认tabspec布局将图标放在顶部 我想通过为tabspec定义自己的布局来居中,但在对style&background进行了多次实验之后,我仍然无法使其看起来像内置布局 因此,我的tabspec布局需要内置的填充和背景,有人知道它们叫什么吗?太多的摆弄-通过为选项卡创建一个固定高度和可变宽度的图标解决了这个问题: private Drawable getTabIcon(byte chainID, Resources res) {

我有一些不同高度的图标,HTC Legend上的默认tabspec布局将图标放在顶部

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


因此,我的tabspec布局需要内置的填充和背景,有人知道它们叫什么吗?

太多的摆弄-通过为选项卡创建一个固定高度和可变宽度的图标解决了这个问题:

    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_标志进行了一些实验,但它很难看,因此选择了图像裁剪。

将样式设置为@android:style/Widget.TabWidget导致:android.content.res.Resources$NotFoundException:File res/drawable mdpi/title_bar\u shadow.9.png,来自可绘制资源ID 0x1030034