android - android中的自定义tabview

标签 android customization tabview

我想设计一个只显示一个选项卡的页面。但是当我只添加一个选项卡时,它占用了可用的全部宽度,但我希望该选项卡只占用很小的空间并且剩余空间留空。我不想添加其他选项卡。始终只显示一个选项卡。代码如下

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/

相关文章:

delphi - 如何自定义测试用例向导生成的 DUnit 测试用例类?

drupal - 在不破坏版本的情况下将自定义字段添加到 drupal 导航菜单

user-interface - 自定义 Mautic 导航

mobile - 选项卡 QML 中的图标

php - 我可以通过 POST/GET 发送多少字节?

java - 以编程方式获取 ScrollView 的子级

java - 如何在 API 24 及更高版本的另一个应用程序中打开文件 - android

android - ListView 并从项目中的 subview 传播单击事件

android - setOnTouchListener 不适用于 android fragment

SwiftUI - 在保持 TabView 可滑动的同时检测长按