如何减少android中的tabize?

时间:2015-02-08 07:06:49

标签: android android-layout android-tabs android-tablelayout android-tabactivity

这是我的标签,它有额外的空格我需要删除它们。 这是我的代码

<?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>

主要活动类:

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

1 个答案:

答案 0 :(得分:0)

试试这段代码:

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

PS:我从here

复制/粘贴它