首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >安卓:在TabHost中对齐中心图像

安卓:在TabHost中对齐中心图像
EN

Stack Overflow用户
提问于 2014-03-07 09:29:13
回答 1查看 448关注 0票数 0

我已经做了一个自定义的TabHost,我只想要图片没有文字在每个标签。我如何对齐标签的中心我的图像?有什么帮助吗?谢谢。这是mi java代码:JAVA

代码语言:javascript
复制
private void cargarTabHost() {

        tabs=(TabHost)findViewById(android.R.id.tabhost);
    tabs.setup(); 

    TabHost.TabSpec spec = tabs.newTabSpec("mitab1");
    spec.setContent(R.id.tab1);
    spec.setIndicator("", getResources().getDrawable(R.drawable.borrar));
    tabs.addTab(spec);

    spec = tabs.newTabSpec("mitab2");
    spec.setContent(R.id.tab2);
    spec.setIndicator("PLANO");
    tabs.addTab(spec);

    tabs.setCurrentTab(0);

    RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    rllp.addRule(RelativeLayout.CENTER_IN_PARENT);

    for (int i = 0; i < tabs.getTabWidget().getTabCount(); i++) {
        tabs.getTabWidget().getChildAt(i).getLayoutParams().height = 75;
        tabs.getTabWidget().getChildAt(i).findViewById(android.R.id.title).
        setLayoutParams(rllp);   
    }

    TabWidget tw = (TabWidget)tabs.findViewById(android.R.id.tabs);

            View tabView = tw.getChildTabViewAt(0);
    tabView.setBackgroundResource(Modulo.cargarColorPestanas(perfilObj.getColor()));

    View tabView2 = tw.getChildTabViewAt(1);
    tabView2.setBackgroundResource(Modulo.cargarColorPestanas(perfilObj.getColor()));

    tabs.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {

            ...
        }
    });
}
EN

回答 1

Stack Overflow用户

发布于 2014-03-07 09:33:53

试试看,我还没试过,但希望能成功。

代码语言:javascript
复制
...
 for (int i = 0; i < tabs.getTabWidget().getTabCount(); i++) {
        tabs.getTabWidget().getChildAt(i).getLayoutParams().height = 75;
        tabs.getTabWidget().getChildAt(i).findViewById(android.R.id.title)
       .setVisibility(View.GONE);
    }
...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22246220

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档