开发者

TabHost.TabSpec layout that looks like the built-in layout

I have some icons of varying height, and the default tabspec layout on my HTC Legend places the icon at the top.

I wanted to center it by defining my own layout for the tabspec, but after many experiments with style & background开发者_如何学C, I still can't make it look like the built-in layout.

So I need the built-in Padding & background for my tabspec layout, anyone knows what they're called?


Too much fiddling about - solved it by creating a fixed-height and variable width icon for the tab:

    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);
}

Did some experimenting with scaling and Paint.ANTI_ALIAS_FLAG, but it was ugly, so image cropping was selected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜