private void scrollToTab(int tabIndex, int positionOffset) {
   final int tabStripChildCount = mTabStrip.getChildCount();
   if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
     return;
   }
   View selectedChild = mTabStrip.getChildAt(tabIndex);
   if (selectedChild != null) {
     int targetScrollX = selectedChild.getLeft() + positionOffset;
     if (tabIndex > 0 || positionOffset > 0) {
       // If we're not at the first child and are mid-scroll, make sure we obey the offset
       targetScrollX -= mTitleOffset;
     }
     scrollTo(targetScrollX, 0);
   }
 }
Example #2
0
  private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
      View tabView = null;
      TextView tabTitleView = null;

      if (mTabViewLayoutId != 0) {
        // If there is a custom tab view layout id set, try and inflate it
        tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
        tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
      }

      if (tabView == null) {
        tabView = createDefaultTabView(getContext());
      }

      if (tabTitleView == null && TextView.class.isInstance(tabView)) {
        tabTitleView = (TextView) tabView;
      }

      tabTitleView.setText(adapter.getPageTitle(i));
      tabView.setOnClickListener(tabClickListener);

      mTabStrip.addView(tabView);
    }
  }
 private void populateTabStrip() {
   final PagerAdapter adapter = mViewPager.getAdapter();
   final View.OnClickListener tabClickListener = new TabClickListener();
   for (int i = 0; i < adapter.getCount(); i++) {
     View tabView = null;
     TextView tabTitleView = null;
     if (mTabViewLayoutId != 0) {
       // If there is a custom tab view layout id set, try and inflate it
       tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
       tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
     }
     if (tabView == null) {
       tabView = createDefaultTabView(getContext());
     }
     if (tabTitleView == null && TextView.class.isInstance(tabView)) {
       tabTitleView = (TextView) tabView;
     }
     if (mDistributeEvenly) {
       LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
       lp.width = 0;
       lp.weight = 1;
     }
     tabTitleView.setText(adapter.getPageTitle(i));
     tabView.setOnClickListener(tabClickListener);
     String desc = mContentDescriptions.get(i, null);
     if (desc != null) {
       tabView.setContentDescription(desc);
     }
     mTabStrip.addView(tabView);
     if (i == mViewPager.getCurrentItem()) {
       tabView.setSelected(true);
     }
   }
 }
 /**
  * Sets the associated view pager. Note that the assumption here is that the pager content (number
  * of tabs and tab titles) does not change after this call has been made.
  */
 public void setViewPager(ViewPager viewPager) {
   mTabStrip.removeAllViews();
   mViewPager = viewPager;
   if (viewPager != null) {
     viewPager.setOnPageChangeListener(new InternalViewPagerListener());
     populateTabStrip();
   }
 }
Example #5
0
  private void scrollToTab(int tabIndex, int positionOffset) {
    final int tabStripChildCount = mTabStrip.getChildCount();
    if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
      return;
    }

    View selectedChild = mTabStrip.getChildAt(tabIndex);
    if (selectedChild != null) {
      // LinearLayout ll = (LinearLayout) selectedChild;
      // Log.i("LOG", "TYPE: "+((TextView) ll.getChildAt(0)).getText());
      // ((TextView) ll.getChildAt(0)).setText("1212121");
      int targetScrollX = selectedChild.getLeft() + positionOffset;

      if (tabIndex > 0 || positionOffset > 0) {
        // If we're not at the first child and are mid-scroll, make sure we obey the offset
        targetScrollX -= mTitleOffset;
      }

      scrollTo(targetScrollX, 0);
    }
  }
  private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
      View tabView = null;
      TextView tabTitleView = null;

      if (mTabViewLayoutId != 0) {
        // If there is a custom tab view layout id set, try and inflate it
        tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
        LinearLayout.LayoutParams loparams = (LinearLayout.LayoutParams) tabView.getLayoutParams();
        loparams.weight = 1;
        //                loparams.height = 50;
        //                loparams.gravity = Gravity.CENTER;
        tabView.setLayoutParams(loparams);
        tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        tabTitleView.setLayoutParams(
            new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f));
      }

      if (tabView == null) {
        tabView = createDefaultTabView(getContext());
        LinearLayout.LayoutParams loparams = (LinearLayout.LayoutParams) tabView.getLayoutParams();
        loparams.weight = 1;
        //                loparams.height = 50;
        //                loparams.gravity = Gravity.CENTER;
        tabView.setLayoutParams(loparams);
      }

      if (tabTitleView == null && TextView.class.isInstance(tabView)) {
        tabTitleView = (TextView) tabView;
      }

      tabTitleView.setText(adapter.getPageTitle(i));
      tabView.setOnClickListener(tabClickListener);

      mTabStrip.addView(tabView);
    }
  }
 public void setSelectedIndicatorColors(int... colors) {
   mTabStrip.setSelectedIndicatorColors(colors);
 }
 public void setCustomTabColorizer(TabColorizer tabColorizer) {
   mTabStrip.setCustomTabColorizer(tabColorizer);
 }
Example #9
0
 /**
  * Sets the colors to be used for tab dividers. These colors are treated as a circular array.
  * Providing one color will mean that all tabs are indicated with the same color.
  */
 public void setDividerColors(int... colors) {
   mTabStrip.setDividerColors(colors);
 }
 public void hideMDividerPaint() {
   mTabStrip.hideMDividerPaint();
 }