示例#1
0
  @Override
  public void onPageScrollStateChanged(int state) {
    if (state == ViewPager.SCROLL_STATE_IDLE) {
      mScrolling = false;
      TextView tv = getTabView(mSelectedPosition);
      if (tv != null) updateIndicator(tv.getLeft(), tv.getMeasuredWidth());
    } else mScrolling = true;

    if (mListener != null) mListener.onPageScrollStateChanged(state);
  }
示例#2
0
  @Override
  public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    if (mListener != null) mListener.onPageScrolled(position, positionOffset, positionOffsetPixels);

    CheckedTextView tv_scroll = getTabView(position);
    CheckedTextView tv_next = getTabView(position + 1);

    if (tv_scroll != null && tv_next != null) {
      int width_scroll = tv_scroll.getWidth();
      int width_next = tv_next.getWidth();
      float distance = (width_scroll + width_next) / 2f;

      int width = (int) (width_scroll + (width_next - width_scroll) * positionOffset + 0.5f);
      int offset =
          (int)
              (tv_scroll.getLeft()
                  + width_scroll / 2f
                  + distance * positionOffset
                  - width / 2f
                  + 0.5f);
      updateIndicator(offset, width);
    }
  }