【问题标题】:Android: align center image in TabHostAndroid:在 TabHost 中对齐中心图像
【发布时间】:2014-04-10 08:55:30
【问题描述】:

我制作了一个自定义 TabHost,我只想要每个选项卡上没有文字的图像。如何对齐图像的标签中心?请问有什么帮助吗?谢谢你。这是mi java代码: JAVA

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) {

            ...
        }
    });
}

【问题讨论】:

    标签: android image alignment android-tabhost


    【解决方案1】:

    尝试这样做,我没有尝试过,但希望它有效。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 2011-02-04
      • 2013-08-19
      • 2016-11-08
      • 1970-01-01
      相关资源
      最近更新 更多