How to manage the width of ActionBar navigation tabs?

前端 未结 3 1656
攒了一身酷
攒了一身酷 2021-02-05 10:48

I am using ActionBarSherlock and have an ActionBar with navigation tabs in it. I want the tabs to auto-size based on the size of the text in them, but there seems to be a style

3条回答
  •  佛祖请我去吃肉
    2021-02-05 10:52

    Override this class in project ActionBarSherlock ./ActionbarSherlock/src/com/actionbarsherlock/internal/widget/ScrollingTabContainerView.java

     @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
         Re-measure if we went beyond our maximum size.
        if (mParent.mMaxTabWidth > 0 && getMeasuredWidth() > mParent.mMaxTabWidth) {
    
          //do nothing , override by me for ActionBarTabs not rezize never
    
        }
    }
    

    Original code from

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    
        // Re-measure if we went beyond our maximum size.
        if (mParent.mMaxTabWidth > 0 && getMeasuredWidth() > mParent.mMaxTabWidth) {
            super.onMeasure(MeasureSpec.makeMeasureSpec(mParent.mMaxTabWidth, MeasureSpec.EXACTLY),
                    heightMeasureSpec);
        }
    }
    

    When run , that code in android 2.3.3 works fine when my Tabs not broken line, but in android 4.4 not works.

提交回复
热议问题