當前位置: 首頁>>代碼示例>>Java>>正文


Java ViewPager.addOnPageChangeListener方法代碼示例

本文整理匯總了Java中android.support.v4.view.ViewPager.addOnPageChangeListener方法的典型用法代碼示例。如果您正苦於以下問題:Java ViewPager.addOnPageChangeListener方法的具體用法?Java ViewPager.addOnPageChangeListener怎麽用?Java ViewPager.addOnPageChangeListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.view.ViewPager的用法示例。


在下文中一共展示了ViewPager.addOnPageChangeListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setViewPager

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
/**
 * Set the {@link ViewPager} associated with this widget indicator.
 *
 * @param pager     {@link ViewPager} to attach
 * @param stepCount The real page count to display (use this if you are using looped viewpager to indicate the real number
 *                  of pages)
 */
public void setViewPager(ViewPager pager, int stepCount) {
    if (this.pager == pager) {
        return;
    }
    if (this.pager != null) {
        pager.removeOnPageChangeListener(this);
    }
    if (pager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }

    this.pager = pager;
    this.stepCount = stepCount;
    currentStep = 0;
    pager.addOnPageChangeListener(this);

    if(showLabels && labels == null) {
        setLabelsUsingPageTitles();
    }

    invalidate();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:30,代碼來源:StepperIndicator.java

示例2: onViewCreatedOk

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
@Override
public void onViewCreatedOk(View view, @Nullable Bundle savedInstanceState) {
    mCbCheck = (AppCompatCheckBox) view.findViewById(R.id.cb_page_check);
    mViewPager = (ViewPager) view.findViewById(R.id.view_pager_page);
    mRlRootView = (RelativeLayout) view.findViewById(R.id.rl_page_root_view);
    mScreenSize = DeviceUtils.getScreenSize(getContext());

    mMediaBeanList = new ArrayList<>();
    if (savedInstanceState != null) {
        List<MediaBean> mediaList = savedInstanceState.getParcelableArrayList(EXTRA_MEDIA_LIST);
        mItemClickPosition = savedInstanceState.getInt(EXTRA_ITEM_CLICK_POSITION);

        if (mediaList != null) {
            mMediaBeanList.addAll(mediaList);
        }
    }
    mMediaPreviewAdapter = new MediaPreviewAdapter(mMediaBeanList,
            mScreenSize.widthPixels, mScreenSize.heightPixels, mConfiguration
            , ThemeUtils.resolveColor(getActivity(), R.attr.gallery_page_bg, R.color.gallery_default_page_bg),
            ContextCompat.getDrawable(getActivity(), ThemeUtils.resolveDrawableRes(getActivity(), R.attr.gallery_default_image, R.drawable.gallery_default_image)));
    mViewPager.setAdapter(mMediaPreviewAdapter);
    mCbCheck.setOnClickListener(this);
    mViewPager.setCurrentItem(mItemClickPosition);
    mViewPager.addOnPageChangeListener(this);
}
 
開發者ID:Loofer,項目名稱:Watermark,代碼行數:26,代碼來源:MediaPageFragment.java

示例3: onCreate

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_animation_new);
    tvNewNews = (TextView) findViewById(R.id.tv_bar_news_news);
    tvNewNews.setSelected(true);
    tvNewNews.setOnClickListener(this);
    tvhotNews = (TextView) findViewById(R.id.tv_bar_news_hot);
    tvhotNews.setOnClickListener(this);
    tvtuiNews = (TextView) findViewById(R.id.tv_bar_news_tui);
    tvtuiNews.setOnClickListener(this);
    vpNews = (ViewPager) findViewById(R.id.vp_news);
    newsFragmentLists = new ArrayList<>();
    newNewsFragment = NewsFragment.newNewsFragment(NewsFragment.NEWSNEWS);
    hotNewsFragment = NewsFragment.newNewsFragment(NewsFragment.NEWSHOT);
    tuiNewsFragment = NewsFragment.newNewsFragment(NewsFragment.NEWSTUI);
    newsFragmentLists.add(newNewsFragment);
    newsFragmentLists.add(hotNewsFragment);
    newsFragmentLists.add(tuiNewsFragment);
    newsViewPagerAdapter = new NewsViewPagerAdapter(getSupportFragmentManager(),newsFragmentLists);
    vpNews.setAdapter(newsViewPagerAdapter);
    vpNews.addOnPageChangeListener(this);
    vpNews.setOffscreenPageLimit(3);
}
 
開發者ID:NicoLiutong,項目名稱:miaosou,代碼行數:25,代碼來源:AnimationNewActivity.java

示例4: setViewPagerCircle

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
/**
 * For circular adapter, where 2 fake page (first and last)
 */
public void setViewPagerCircle(ViewPager viewPager) {
  k = 1;
  viewPager.addOnPageChangeListener(this);
  max = viewPager.getAdapter().getCount();
  current = viewPager.getCurrentItem();
  if (current == 0) {
    current++;
    viewPager.setCurrentItem(current);
  }
  if (current == max) {
    current--;
    viewPager.setCurrentItem(current);
  }
  update();
}
 
開發者ID:AtlantPlatform,項目名稱:atlant-android,代碼行數:19,代碼來源:IndicatorCircleView.java

示例5: onCreate

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_top_tabs);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Create the adapter that will return a fragment for each of the three
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);

    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));

    final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

}
 
開發者ID:PacktPublishing,項目名稱:Hands-On-Android-UI-Development,代碼行數:31,代碼來源:TopTabsActivity.java

示例6: attachToViewpager

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
/**
 * 綁定viewpager
 */
public void attachToViewpager(ViewPager viewPager) {
    viewPager.addOnPageChangeListener(this);
    count = viewPager.getAdapter().getCount();
    moveToNext();
    mDrection=DIRECTION_RIGHT;
    invalidate();
}
 
開發者ID:yangchaojiang,項目名稱:ZoomPreviewPicture,代碼行數:11,代碼來源:BezierBannerView.java

示例7: onCreate

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nav_main);
    mNavigation = (BottomNavigationView) findViewById(R.id.navigation);
    mNavigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    mVp = (ViewPager) findViewById(R.id.vp);
    mVp.setAdapter(new PagerAdapter(getSupportFragmentManager()));
    mVp.addOnPageChangeListener(new PageSelectedListener());
}
 
開發者ID:halohoop,項目名稱:AndroidDigIn,代碼行數:11,代碼來源:NavMainActivity.java

示例8: setViewPager

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
/**
 * 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) {
  tabStrip.removeAllViews();

  this.viewPager = viewPager;
  if (viewPager != null && viewPager.getAdapter() != null) {
    viewPager.addOnPageChangeListener(new InternalViewPagerListener());
    populateTabStrip();
  }
}
 
開發者ID:huashengzzz,項目名稱:SmartChart,代碼行數:14,代碼來源:SmartTabLayout.java

示例9: attach2ViewPage

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
/**
 * ����ViewPager������scroll���иı�bezRound
 */
public void attach2ViewPage(ViewPager vPage) {
    vPage.addOnPageChangeListener(this);
    this.mViewPage = vPage;
    if (PagerAdapter.class.isInstance(vPage.getAdapter())) {
        this.default_round_count = vPage.getAdapter().getCount();
        initCountPos();
    }
}
 
開發者ID:RealMoMo,項目名稱:BezierRoundView,代碼行數:12,代碼來源:BezierRoundView .java

示例10: onCreate

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_v2ex);

  toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setTitle(R.string.v2ex);
  toolbar.setNavigationOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      V2exActivity.this.finish();
    }
  });

  tabLayout = (TabLayout) findViewById(R.id.tabLayout);
  viewPager = (ViewPager) findViewById(R.id.viewPager);

  tabLayout.addOnTabSelectedListener(this);
  viewPager.addOnPageChangeListener(this);

  viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
    @Override
    public Fragment getItem(int position) {
      switch (position) {
        case 0:
          return v2exLatestFragment;
        case 1:
          return v2exHotFragment;
      }
      return null;
    }

    @Override
    public int getCount() {
      return 2;
    }
  });

}
 
開發者ID:tomoya92,項目名稱:android-apps,代碼行數:40,代碼來源:V2exActivity.java

示例11: setViewPager

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
public void setViewPager(ViewPager viewPager) {
  k = 0;
  viewPager.addOnPageChangeListener(this);
  max = viewPager.getAdapter().getCount();
  current = viewPager.getCurrentItem();
  update();
}
 
開發者ID:AtlantPlatform,項目名稱:atlant-android,代碼行數:8,代碼來源:IndicatorCircleView.java

示例12: addPagerData

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
public void addPagerData(PageBean bean, ViewPager viewPager) {
    if (bean != null){
        mCount = bean.datas.size();
        //這裏加小圓點
        for (int i = 0; i < mCount; i++) {
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            if (i == mCount - 1){ //防止indicator的寬度為wrap_content,放大後被遮蓋住的問題
                params.setMargins(mLeftMargin,0,mLeftMargin,0);
            }else{
                params.setMargins(mLeftMargin,0,0,0);
            }

            ImageView imageView = new ImageView(mContext);
        /*    if (mSelector == 0){
            }else {
            }*/
            imageView.setBackgroundResource(mSelector);
            imageView.setLayoutParams(params);
            imageView.setAlpha(mAlpha_min);

            addView(imageView);
        }
    }
    if (bean.openview != null){
        mOpenView = bean.openview;
    }
    if (viewPager != null){
        viewPager.addOnPageChangeListener(this);
    }
}
 
開發者ID:LillteZheng,項目名稱:ViewPagerHelper,代碼行數:33,代碼來源:ZoomIndicator.java

示例13: setupViewPager

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
private void setupViewPager(ViewPager viewPager) {
    adapter = new Adapter(getSupportFragmentManager());
    adapter.addFragment(new TransactionOverviewFragment(), getString(R.string.chuck_overview));
    adapter.addFragment(TransactionPayloadFragment.newInstance(TYPE_REQUEST), getString(R.string.chuck_request));
    adapter.addFragment(TransactionPayloadFragment.newInstance(TYPE_RESPONSE), getString(R.string.chuck_response));
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(new SimpleOnPageChangedListener() {
        @Override
        public void onPageSelected(int position) {
            selectedTabPosition = position;
        }
    });
    viewPager.setCurrentItem(selectedTabPosition);
}
 
開發者ID:jgilfelt,項目名稱:chuck,代碼行數:15,代碼來源:TransactionActivity.java

示例14: ShadowTransformer

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
public ShadowTransformer(ViewPager viewPager, CardAdapter adapter) {
    mViewPager = viewPager;
    viewPager.addOnPageChangeListener(this);
    mAdapter = adapter;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:6,代碼來源:ShadowTransformer.java

示例15: setupWithViewPager

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
private void setupWithViewPager(@Nullable final ViewPager viewPager, boolean autoRefresh,
          boolean implicitSetup) {
  if (mViewPager != null) {
    // If we've already been setup with a ViewPager, remove us from it
    if (mPageChangeListener != null) {
      mViewPager.removeOnPageChangeListener(mPageChangeListener);
    }
    if (mAdapterChangeListener != null) {
      mViewPager.removeOnAdapterChangeListener(mAdapterChangeListener);
    }
  }

  if (mCurrentVpSelectedListener != null) {
    // If we already have a tab selected listener for the ViewPager, remove it
    removeOnTabSelectedListener(mCurrentVpSelectedListener);
    mCurrentVpSelectedListener = null;
  }

  if (viewPager != null) {
    mViewPager = viewPager;

    // Add our custom OnPageChangeListener to the ViewPager
    if (mPageChangeListener == null) {
      mPageChangeListener = new TabLayoutOnPageChangeListener(this);
    }
    mPageChangeListener.reset();
    viewPager.addOnPageChangeListener(mPageChangeListener);

    // Now we'll add a tab selected listener to set ViewPager's current item
    mCurrentVpSelectedListener = new ViewPagerOnTabSelectedListener(viewPager);
    addOnTabSelectedListener(mCurrentVpSelectedListener);

    final PagerAdapter adapter = viewPager.getAdapter();
    if (adapter != null) {
      // Now we'll populate ourselves from the pager adapter, adding an observer if
      // autoRefresh is enabled
      setPagerAdapter(adapter, autoRefresh);
    }

    // Add a listener so that we're notified of any adapter changes
    if (mAdapterChangeListener == null) {
      mAdapterChangeListener = new AdapterChangeListener();
    }
    mAdapterChangeListener.setAutoRefresh(autoRefresh);
    viewPager.addOnAdapterChangeListener(mAdapterChangeListener);

    // Now update the scroll position to match the ViewPager's current item
    setScrollPosition(viewPager.getCurrentItem(), 0f, true);
  } else {
    // We've been given a null ViewPager so we need to clear out the internal state,
    // listeners and observers
    mViewPager = null;
    setPagerAdapter(null, false);
  }

  mSetupViewPagerImplicitly = implicitSetup;
}
 
開發者ID:commonsguy,項目名稱:cwac-crossport,代碼行數:58,代碼來源:TabLayout.java


注:本文中的android.support.v4.view.ViewPager.addOnPageChangeListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。