【问题标题】:custom tabview in androidandroid中的自定义tabview
【发布时间】:2011-09-05 11:57:52
【问题描述】:

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

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);

【问题讨论】:

    标签: android customization tabview


    【解决方案1】:

    使用tabHost.getTabWidget().getChildAt(0).getLayoutParams().width =(int) 30;也设置layout_width="wrap_content"

    【讨论】:

      【解决方案2】:

      在您的 xml 中,通过将可见性设置为消失来隐藏选项卡小部件。而是使用一个按钮。在按钮处理程序中,您可以使用类似

      的代码
      public void tabHandler(View target){
          artistButton.setSelected(false);
          albumButton.setSelected(false);
          if(target.getId() == R.id.artist_id){
              tabHost.setCurrentTab(0);
              artistButton.setSelected(true);
          } else if(target.getId() == R.id.album_id){
              tabHost.setCurrentTab(1);
              albumButton.setSelected(true);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-02
        • 1970-01-01
        • 2019-06-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多