【问题标题】:How to change size of tabs如何更改选项卡的大小
【发布时间】:2011-06-23 12:22:53
【问题描述】:

实际上我在我的应用程序中创建了一个选项卡。这里有三个选项卡..但问题是我无法在选项卡中管理样式,而且我希望一个选项卡的大小大于我发送的其他两个选项卡代码你请检查它..

XML 代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent" 
android:layout_width="match_parent" 
android:orientation="horizontal"
>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5dp">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" 
        />

</LinearLayout>

Java 代码:

setContentView(R.layout.main);
    Resources res = getResources(); 
    TabHost tabHost = getTabHost();  
    TabHost.TabSpec spec; 
    Intent intent;  

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, ContactActivity.class);

    spec = tabHost.newTabSpec("Contacts").setIndicator("Contacts",
                      res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(intent);
    tabHost.addTab(spec);


    // Do the same for the other tabs
    intent = new Intent().setClass(this, CallActivity.class);
    spec = tabHost.newTabSpec("Call").setIndicator("Call",
                      res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, MyInfoActivity.class);
    spec = tabHost.newTabSpec("My Info").setIndicator("MyInfo",
                      res.getDrawable(R.drawable.ic_tab_artists))
                  .setContent(intent);
    tabHost.addTab(spec);

   tabHost.setCurrentTab(2);

【问题讨论】:

  • getTabHost()的方法是什么?我在片段中使用标签,所以我的主机活动是FragmentActivity

标签: android


【解决方案1】:

这里是改变标签大小的代码

 Display display = getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

       TabHost mTabHost = getTabHost();
      
       mTabHost.addTab(mTabHost.newTabSpec("tab_test1")
               .setIndicator((""),getResources().getDrawable(R.drawable.mzl_05))
         .setContent(new Intent(this, NearBy.class)));
       mTabHost.addTab(mTabHost.newTabSpec("tab_test2")
               .setIndicator((""),getResources().getDrawable(R.drawable.mzl_08))
         .setContent(new Intent(this, SearchBy.class)));
               mTabHost.setCurrentTab(0);
               mTabHost.getTabWidget().getChildAt(0).setLayoutParams(new
                 LinearLayout.LayoutParams((width/2)-2,50));
          mTabHost.getTabWidget().getChildAt(1).setLayoutParams(new
                     LinearLayout.LayoutParams((width/2)-2,50));

【讨论】:

  • 它适用于所有设备吗?我们还需要以编程方式获取高度。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-14
  • 1970-01-01
  • 2016-07-22
  • 1970-01-01
  • 2017-02-22
  • 1970-01-01
相关资源
最近更新 更多