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

发布于 2024-10-07 17:08:24 字数 184 浏览 0 评论 0原文

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

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

所以我需要内置的 Padding &我的 tabspec 布局的背景,有人知道它们叫什么吗?

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, 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心激荡 2024-10-14 17:08:24

太多的摆弄 - 通过为选项卡创建固定高度和可变宽度的图标来解决它:

    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 的实验,但它很丑,所以选择了图像裁剪。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文