当前位置: 首页>>代码示例>>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;未经允许,请勿转载。