Android Tab 间距/填充选项

标签 android

使用示例 http://developer.android.com/guide/tutorials/views/hello-tabwidget.html通过向布局添加 Horizo​​ntalScrollView 然后复制选项卡的实例,我做了一些小改动。有没有办法更好地隔开或添加填充,以使选项卡不会聚在一起?

对 main.xml 的更改

<HorizontalScrollView android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:fillViewport="true"
                      android:scrollbars="none">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </HorizontalScrollView>

在公共(public)类 HelloTabWidget 中扩展了我添加的 TabActivity

    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));       
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3)); 

最佳答案

编辑:OP 通过这样做解决了问题:

for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) 
    { 
    mTabHost.getTabWidget().getChildAt(i).setPadding(40,0,40,0); 
    }

顺便说一句,标签在新版本中已被弃用。可以考虑学习Fragments .

关于Android Tab 间距/填充选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9187002/

相关文章:

android - Youtube 控件(播放/暂停)在播放器恢复/Activity 恢复后不起作用

java - 从系统应用程序重新安装/系统;

android - 如何更改Chip View 的字体?

java - Android(Java 不是 C/C++)插件可以改变统一纹理吗?

android - MapView/MapActivity 在某些设备上崩溃

java - "How to fix this post HTTP request using Android Studio?"

android - 在Android应用程序中强制关闭时如何在运行时获取日志

android - 将径向渐变设置为窗口背景

Android - Espresso 如何在点击并移动到另一个 Activity 后测试 View

android - 在 Android 设备上拆分蓝牙数据