【问题标题】:how to reduce the tabsize in android?如何减少android中的tabsize?
【发布时间】:2015-02-08 07:06:49
【问题描述】:

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

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

如果我这样做,此文本将被隐藏。

当我降低高度时,它会变成这样,并且文本也会隐藏

【问题讨论】:

  • 为什么要使用已弃用的 TabActivity 。请使用 FragmentActivity 代替 TabActivity

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


【解决方案1】:

试试这个代码:

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

PS:我从here复制/粘贴它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-16
    • 1970-01-01
    • 2022-01-11
    • 2021-04-11
    • 2014-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多