0

这是我的选项卡它有额外的一些空间,我需要删除它们。 这是我的代码如何减少android中的tabsize?

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:padding="0dip" 
      android:layout_height="wrap_content" /> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"/> 
    </LinearLayout> 
</TabHost> 

MainActivity类别:

public class MainActivity 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(); 

     // Tab for Photos 
     TabSpec photospec = tabHost.newTabSpec("Photos"); 
     // setting Title and Icon for the Tab 
     photospec.setIndicator("Photos"); 
     // photospec.setText("da"); 
     Intent photosIntent = new Intent(this, SplashActivity.class); 
     photospec.setContent(photosIntent); 

     // Tab for Videos 
     TabSpec videospec = tabHost.newTabSpec("Videos"); 
     videospec.setIndicator("Videos"); 
     Intent videosIntent = new Intent(this, MainActivity.class); 
     videospec.setContent(videosIntent); 

     // Adding all TabSpec to TabHost 
     tabHost.addTab(photospec); // Adding photos tab 

     tabHost.addTab(videospec); // Adding videos tab 
    } 
} 

我试图改变标签的大小,布局像这样

<TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="23dp" 
      android:padding="0dip" /> 

如果我这样做的文字将被隐藏。 enter image description here

当我降低它变得像这样和文字也隐藏 enter image description here

+0

为什么你贴使用弃用的TabActivity。请使用FragmentActivity代替TabActivity – 2015-02-08 07:34:10

回答

0

试试这个代码高度:

for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) { 
    tabHost.getTabWidget().getChildAt(i).getLayoutParams().height /=2; 
} 

PS:我复制/从here