我想设计一个只显示一个选项卡的页面。但是当我只添加一个选项卡时,它占用了可用的全部宽度,但我希望该选项卡只占用很小的空间并且剩余空间留空。我不想添加其他选项卡。始终只显示一个选项卡。代码如下
public class TabViewActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, FirstTab.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("firstTab").setIndicator("First Tab")
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);
最佳答案
使用tabHost.getTabWidget().getChildAt(0).getLayoutParams().width =(int) 30;
同时设置layout_width="wrap_content"
关于android - android中的自定义tabview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7307724/