如何在Android中的标签按钮之间添加空格?

问题描述

| 我需要用空格分隔选项卡按钮,我尝试为视图设置边距,然后将其添加为选项卡,但是它不起作用,我还考虑过将空视图添加为分隔符,但是还没有尝试过,是否有有任何标准的方法可以做到相同的效果吗? 谢谢!     

解决方法

这是这样的:
TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
final int tabChildrenCount = tabWidget.getChildCount();
View currentView;
for (int i = 0; i < tabChildrenCount; i++) {
    currentView = tabWidget.getChildAt(i);
    LinearLayout.LayoutParams currentLayout =
        (LinearLayout.LayoutParams) currentView.getLayoutParams();
    currentLayout.setMargins(0,5,0);
}
tabWidget.requestLayout();
    ,即使对于我的问题,这也是一个很好的解决方案!非常感谢!我用它来实现窗口小部件中第一个项目和最后一个项目之后的空间,以便有可能将它们滚动到中心,而无需添加其他(并且令人不安,因为窗口小部件并不期望这种愚蠢的东西)不可见的按钮。
    //pump up space for first entry on the left and last entry on the right!
    Display display = getWindowManager().getDefaultDisplay();
    //Point size = new Point();
    int width = display.getWidth();

    View currentView = mTabHost.getTabWidget().getChildAt(0);
    LinearLayout.LayoutParams currentLayout = (LinearLayout.LayoutParams) currentView.getLayoutParams();
    currentLayout.setMargins(currentLayout.leftMargin + width/2,currentLayout.topMargin,currentLayout.rightMargin,currentLayout.bottomMargin);
    currentView = mTabHost.getTabWidget().getChildAt(mTabHost.getTabWidget().getChildCount()-1);
    currentLayout = (LinearLayout.LayoutParams) currentView.getLayoutParams();
    currentLayout.setMargins(currentLayout.leftMargin,currentLayout.rightMargin  + width/2,currentLayout.bottomMargin);      
    mTabHost.getTabWidget().requestLayout();
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...