如何以编程方式设置Tab的位置?

时间:2011-10-25 09:55:55

标签: android android-tabhost

我正在使用tab-host开发一个示例应用程序,我已经实现了它。 这是我的问题?我将逐步描述它。

  • 假设有5个位置为0,1,2,3,4的标签。当我选择第四个标签时,应该在第二个标签上将其替换。

我如何克服这个问题?

2 个答案:

答案 0 :(得分:1)

如果我理解正确的话,这是前进的

tabHost.setCurrentTab(index)

> EDITS

您可以使标签隐藏

如 如果你想要在0号位置看不见的标签,那么它就是如下。

      tabWidget = (TabWidget) findViewById(android.R.id.tabs);
      tabWidget.getChildTabViewAt(0).setVisibility(View.GONE);

如果您想让它可见,请按以下步骤

 tabWidget.getChildTabViewAt(0).setVisibility(View.VISIBLE);

但是如果要删除旧标签并将其替换为新标签。然后我不知道是否可能

答案 1 :(得分:0)

你应该试试这个:

FrameLayout frame = tabHost.getTabContentView();

View view1 = frame.getChildAt(pos1);
View view2 = frame.getChildAt(pos2);

frame.removeViewAt(pos1);
frame.addView(view2, pos1);

frame.removeViewAt(pos2);
frame.addView(view1, pos2);

这应该使用pos1位置的标签切换pos2位置的标签 我没有检查它,但它应该工作:)

相关问题