如何去除选项卡控件之间的空白?

3
我想去掉选项卡小部件之间的间距。默认情况下,选项卡之间有大约1像素的间距。我知道一些应用程序,如foursquare或posterous可以去掉它。代码应该是什么样子?我正在使用2.3 API。
谢谢你的帮助。

"tabwidgets之间的间距是什么?" - CommonsWare
5个回答

6
你可以使用getTabHost().getTabWidget().setDividerDrawable(R.drawable.empty_divider)方法,其中R.drawable.empty_divider是一个简单的形状,大小为0px,例如:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >
    <size
        android:width="0px"
        android:color="@android:color/black"
        android:dashWidth="0px"
        android:dashGap="0px" />
</shape>

嗨,感谢你的帮助。非常感激。我将此XML保存为drawable文件夹下的empty_divider.xml。但是,当我按照你的说明调用它时,它仍然无法正常工作。我有遗漏什么吗? - Joshua Partogi
由于某些原因,StackOverflow的编辑器切掉了最后一个闭合标签,请查看此手册页面:http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape - Grekov Serg

5

TabWidget android:showDividers="none"


1
嗨Shuidi,欢迎来到StackOverflow!如果您能提供一些更详细的描述,那对用户会更有帮助。感谢您的回答。 - Renjith K N

4

如果你的构建目标是Honeycomb或更高版本,你可以使用以下代码。

if (Integer.parseInt(Build.VERSION.SDK) >= Build.VERSION_CODES.HONEYCOMB) {
    tabHost.getTabWidget().setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
}

非常感谢您提供的解决方案...我在ICS设备上遇到了类似的问题,您的解决方案完美地解决了我的问题。 - Zeba

3
我用以下代码解决了同样的问题:
```python 我解决了这个问题:
```
 tabHost.getTabWidget().setDividerDrawable(null);

2
您可以在布局的XML中添加android:showDividers="none"。
<TabWidget
    android:id="@android:id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:showDividers="none" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接