本文介绍了我们怎样才能在Android的tabhost每个选项卡中指定的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的应用程序tabhost。我们可以给每个标签单独width属性?即,一个具有较大的宽度和其他较小的?请给我品尝example.if可能的手段给我code。

编辑:

 公共类TabBarSimple扩展TabActivity {
/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);    的setContentView(R.layout.main);    TabHost tabHost = getTabHost();
    TabHost.TabSpec规范;
    意图意图;    则tabspec dbspec = tabHost.newTabSpec(仪表板);
    dbspec.setIndicator(仪表盘,getResources()getDrawable(R.drawable.dashboard));    意图dbIntent =新意图(这一点,PhotosActivity.class);
    dbspec.setContent(dbIntent);
    tabHost.addTab(dbspec);    则tabspec orderspec = tabHost.newTabSpec(订单);
    orderspec.setIndicator(订单,getResources()getDrawable(R.drawable.orders));    意图orderIntent =新意图(这一点,SongsActivity.class);
    orderspec.setContent(orderIntent);
    tabHost.addTab(orderspec);
    则tabspec settingspec = tabHost.newTabSpec(客户);
    settingspec.setIndicator(客户,getResources()getDrawable(R.drawable.customers));
    意图settingIntent =新意图(这一点,VideosActivity.class);
    settingspec.setContent(settingIntent);
    tabHost.addTab(settingspec);
    则tabspec aboutspec = tabHost.newTabSpec(设置);
    aboutspec.setIndicator(设置,ge​​tResources()getDrawable(R.drawable.settings));
    意图aboutIntent =新意图(这一点,PhotosActivity.class);
    aboutspec.setContent(aboutIntent);
    tabHost.addTab(aboutspec);
    则tabspec logoutspec = tabHost.newTabSpec(注销);
    logoutspec.setIndicator(注销,getResources()getDrawable(R.drawable.logout));
    意图logoutIntent =新意图(这一点,SongsActivity.class);
    logoutspec.setContent(logoutIntent);
    tabHost.addTab(logoutspec);
    的for(int i = 0; I< tabHost.getTabWidget()getChildCount();我++)
    {
    //tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor(\"#8A4117));
    。tabHost.getTabWidget()getChildAt(ⅰ).setBackgroundResource(R.drawable.tab_indicator);
    tabHost.getTabWidget()getChildAt(0).getLayoutParams()宽度= 100。。
    tabHost.getTabWidget()getChildAt(1).getLayoutParams()宽度= 50。;
    }
    tabHost.getTabWidget()setCurrentTab(0)。
    //tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor(\"#C35817));
    tabHost.getTabWidget()getChildAt(0).setBackgroundResource(R.drawable.tab_indicator)。     }    公共无效onTabChanged(字符串tabId){
          TabHost tabHost = getTabHost();
    // TODO自动生成方法存根
    的for(int i = 0; I< tabHost.getTabWidget()getChildCount();我++)
    {
    //tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor(\"#8A4117));
    。tabHost.getTabWidget()getChildAt(ⅰ).setBackgroundResource(R.drawable.tab_indicator);
    }
    //tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor(\"#C35817\"));
    tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.tab_indicator);
    }     }


解决方案

您可以通过下面的code ++实现这一点 - :

  tabHost.getTabWidget()getChildAt(0).getLayoutParams()宽= 50;

I am using tabhost in my application. Can we give separate width property for each tab? i.e, one with larger width and other with smaller?please give me sample example.if possible means give me code.

EDIT:

public class TabBarSimple extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);



    TabHost tabHost = getTabHost();
    TabHost.TabSpec spec;
    Intent intent;

    TabSpec dbspec = tabHost.newTabSpec("DashBoard");
    dbspec.setIndicator("Dashboard", getResources().getDrawable(R.drawable.dashboard));

    Intent dbIntent = new Intent(this, PhotosActivity.class);
    dbspec.setContent(dbIntent);
    tabHost.addTab(dbspec);

    TabSpec orderspec = tabHost.newTabSpec("Orders");
    orderspec.setIndicator("Orders", getResources().getDrawable(R.drawable.orders));

    Intent orderIntent = new Intent(this, SongsActivity.class);
    orderspec.setContent(orderIntent);
    tabHost.addTab(orderspec);
    TabSpec settingspec = tabHost.newTabSpec("Customers");
    settingspec.setIndicator("Customers", getResources().getDrawable(R.drawable.customers));
    Intent settingIntent = new Intent(this, VideosActivity.class);
    settingspec.setContent(settingIntent);
    tabHost.addTab(settingspec);
    TabSpec aboutspec = tabHost.newTabSpec("Settings");
    aboutspec.setIndicator("Settings", getResources().getDrawable(R.drawable.settings));
    Intent aboutIntent = new Intent(this, PhotosActivity.class);
    aboutspec.setContent(aboutIntent);
    tabHost.addTab(aboutspec);
    TabSpec logoutspec = tabHost.newTabSpec("Logout");
    logoutspec.setIndicator("Logout", getResources().getDrawable(R.drawable.logout));
    Intent logoutIntent = new Intent(this, SongsActivity.class);
    logoutspec.setContent(logoutIntent);
    tabHost.addTab(logoutspec);


    for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
    {
    //tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#8A4117"));
    tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_indicator);
    tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 100;
    tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 50;
    }
    tabHost.getTabWidget().setCurrentTab(0);
    //tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#C35817"));
    tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.tab_indicator);

     }

    public void onTabChanged(String tabId) {
          TabHost tabHost = getTabHost();
    // TODO Auto-generated method stub
    for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
    {
    //tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#8A4117"));
    tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_indicator);
    }
    //tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#C35817"));
    tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.tab_indicator);
    }

     }
解决方案

You can achieve this by the code below -:

tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 50;

这篇关于我们怎样才能在Android的tabhost每个选项卡中指定的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 21:34