@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); ViewPager pager = (ViewPager) findViewById(R.id.parent); pager.setOffscreenPageLimit(1); pager.setAdapter( new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public android.support.v4.app.Fragment getItem(int position) { return new ExampleFragment(String.valueOf(position)); } @Override public int getCount() { return 5; } }); LifeCycleRetriever.with(this) .addListener( new LifecycleListener() { @Override public void onLifeCycleStateChange(@LifeCycle.LifeCycleState int life, int level) { Log.e("tag", "ActivityLifeCycle,State:" + haha(life)); } }); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setTheme(android.R.style.Theme_Light); m_vp = (ViewPager) findViewById(R.id.viewpager); pagerTabStrip = (PagerTabStrip) findViewById(R.id.pagertab); // 设置下划线的颜色 pagerTabStrip.setTabIndicatorColor(getResources().getColor(android.R.color.holo_green_dark)); // 设置背景的颜色 pagerTabStrip.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_dark)); pagerTitleStrip = (PagerTitleStrip) findViewById(R.id.pagertab); // 设置背景的颜色 pagerTitleStrip.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_dark)); mfragment1 = new fragment1(); mfragment2 = new fragment2(); mfragment3 = new fragment3(); fragmentList = new ArrayList<Fragment>(); fragmentList.add(mfragment1); fragmentList.add(mfragment2); fragmentList.add(mfragment3); titleList.add("第一页 "); titleList.add("第二页"); titleList.add("第三页 "); m_vp.setAdapter(new MyViewPagerAdapter(getSupportFragmentManager())); m_vp.setOffscreenPageLimit(1); }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void init(Context context) { // Disable clipping of children so non-selected pages are visible setClipChildren(false); // Child clipping doesn't work with hardware acceleration in Android 3.x/4.x // You need to set this value here if using hardware acceleration in an // application targeted at these releases. if (Build.VERSION.SDK_INT >= 11) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } // 添加ViewPager mPager = new ViewPager(context); mPager.setId(R.id.pager); // If hardware acceleration is enabled, you should also remove // clipping on the pager for its children. mPager.setClipChildren(false); mPager.setPageMargin(pageMargin); mPager.setOnPageChangeListener(this); // Necessary or the pager will only have one extra page to show // make this at least however many pages you can see mPager.setOffscreenPageLimit(calcOffscreenPageLimit()); mPager.setLayoutParams( new FrameLayout.LayoutParams(pageWidth, pageHeight, Gravity.CENTER_HORIZONTAL)); this.addView(mPager); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (getIntent().hasExtra("user")) { mCurrentUser = getIntent().getExtras().getParcelable("user"); } if (mCurrentUser == null) { mCurrentUser = new User("name", "level"); } // set custom toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); if (mToolbar != null) { setSupportActionBar(mToolbar); } mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); // the drawer. mNavigationDrawerFragment.setUp( R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); // the pager mArticlePagerAdapter = new UserMetricsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mArticlePagerAdapter); mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs); mSlidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.white)); mSlidingTabLayout.setViewPager(mViewPager); mViewPager.setOffscreenPageLimit(3); }
private void initViewPager() { viewPagerAdapter = AdapterLess.$pager( getSupportFragmentManager(), getResources().getStringArray(R.array.must_titles).length, new AdapterLess.FullFragmentPagerCallBack() { @Override public Fragment getItem(int i) { Fragment fragment; if (i == 0) { fragment = new MustListFragment(); } else if (i == 1) { fragment = new MustListFragment(); } else { fragment = new HomeDigestListFragment(); } return fragment; } @Override public String getPageTitle(int i) { return getResources().getStringArray(R.array.must_titles)[i]; } }); viewPager.setOffscreenPageLimit(3); viewPager.setAdapter(viewPagerAdapter); tabLayout.setupWithViewPager(viewPager); }
private void initChapters(ArrayList<Chapter> chapters) { addChapters(chapters); Chapter chapter = null; if (getIntent().hasExtra(EXTRA_GROUP_ID)) { String chapterId = getIntent().getStringExtra(EXTRA_GROUP_ID); for (Chapter c : chapters) { if (c.getGplusId().equals(chapterId)) { chapter = c; break; } } if (chapter == null) chapter = chapters.get(0); } else { chapter = chapters.get(0); } getSupportActionBar().setSelectedNavigationItem(mSpinnerAdapter.getPosition(chapter)); mViewPager.setAdapter(mViewPagerAdapter); mViewPager.setOffscreenPageLimit(2); mIndicator.setViewPager(mViewPager); if (SECTION_EVENTS.equals(getIntent().getStringExtra(EXTRA_SECTION))) { mHandler.postDelayed( new Runnable() { @Override public void run() { mViewPager.setCurrentItem(2, true); } }, 500); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_open_image); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); viewPager = (ViewPager) findViewById(R.id.gallery_view_pager); 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(); } }); usePicasso = getIntent().getBooleanExtra("usePicasso", false); int position = getIntent().getIntExtra("position", 0); Log.d("vvk", "OpenImageActivity position is " + position + " usePicasso is " + usePicasso); GalleryPagerAdapter pagerAdapter = new GalleryPagerAdapter( getSupportFragmentManager(), getApplicationContext(), GalleryActivity.imageFiles, usePicasso); viewPager.setAdapter(pagerAdapter); viewPager.setCurrentItem(position); viewPager.setOffscreenPageLimit(3); // viewPager.setPageMargin(200); viewPager.setPageMarginDrawable(R.drawable.ic_doctor_default_blue); // // viewPager.setForeground(getResources().getDrawable(R.drawable.ic_doctor_default_blue,null)); // viewPager.set viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { Log.d( "mytab", "position is " + position + " positionoffset " + positionOffset + " offsetpixels " + positionOffsetPixels); } @Override public void onPageSelected(int position) { Log.d("mytab", "position is " + position); } @Override public void onPageScrollStateChanged(int state) { Log.d("mytab", "state is " + state); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_awesomedesign); ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setOffscreenPageLimit(3); PageAdapter a = new PageAdapter(getSupportFragmentManager()); pager.setAdapter(a); AlertDialog.Builder b = new AlertDialog.Builder(this); b.setTitle("This is a ViewPager."); b.setMessage("Swipe left and right for more awesome design examples!"); b.setPositiveButton( "OK", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); b.show(); }
/** {@inheritDoc} */ @Override public View onCreateView( final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { // The View for the fragment's UI final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_music_browser_phone, container, false); // Initialize the adapter mPagerAdapter = new PagerAdapter(getActivity()); final MusicFragments[] mFragments = MusicFragments.values(); for (final MusicFragments mFragment : mFragments) { mPagerAdapter.add(mFragment.getFragmentClass(), null); } // Initialize the ViewPager mViewPager = (ViewPager) rootView.findViewById(R.id.fragment_home_phone_pager); // Attch the adapter mViewPager.setAdapter(mPagerAdapter); // Offscreen pager loading limit mViewPager.setOffscreenPageLimit(mPagerAdapter.getCount() - 1); // Start on the last page the user was on mViewPager.setCurrentItem(mPreferences.getStartPage()); // Initialze the TPI final TitlePageIndicator pageIndicator = (TitlePageIndicator) rootView.findViewById(R.id.fragment_home_phone_pager_titles); // Attach the ViewPager pageIndicator.setViewPager(mViewPager); // Scroll to the current artist, album, or song pageIndicator.setOnCenterItemClickListener(this); return rootView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user_detail); ButterKnife.bind(this); // 设置切换activity对应的控件 ViewCompat.setTransitionName(imgAvatar, NAME_IMG_AVATAR); // 设置头像 String avatarUrl = getIntent().getStringExtra("avatarUrl"); if (!TextUtils.isEmpty(avatarUrl)) { Picasso.with(this).load(avatarUrl).placeholder(R.drawable.image_placeholder).into(imgAvatar); } // 用户名 loginName = getIntent().getStringExtra("loginName"); if (!TextUtils.isEmpty(loginName)) { tvLoginName.setText(loginName); } adapter = new ViewPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(adapter); viewPager.setOffscreenPageLimit(adapter.getCount()); tabLayout.setupWithViewPager(viewPager); getUserAsyncTask(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState, R.layout.view_pager_multi_fragment_demo); viewPager = (ViewPager) findViewById(R.id.view_pager); indexText = (TextView) findViewById(R.id.view_pager_index); viewPagerContainer = (RelativeLayout) findViewById(R.id.pager_layout); viewPager.setAdapter(new MyPagerAdapter()); // to cache all page, or we will see the right item delayed viewPager.setOffscreenPageLimit(TOTAL_COUNT); viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.page_margin)); viewPager.setOnPageChangeListener(new MyOnPageChangeListener()); viewPagerContainer.setOnTouchListener( new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // dispatch the events to the ViewPager, to solve the problem that we can swipe only the // middle view. return viewPager.dispatchTouchEvent(event); } }); indexText.setText(new StringBuilder().append("1/").append(TOTAL_COUNT)); }
private void initViews() { myclick = new MyOnClick(); myPageChange = new MyPageChangeListener(); viewPager = (ViewPager) findViewById(R.id.viewpager_content); viewPager.setAdapter(fragmentPagerAdapter); viewPager.setOnPageChangeListener(myPageChange); viewPager.setOffscreenPageLimit(4); layout_home = (RelativeLayout) findViewById(R.id.layout_home); layout_folders = (RelativeLayout) findViewById(R.id.layout_folders); layout_friends = (RelativeLayout) findViewById(R.id.layout_friends); layout_settings = (RelativeLayout) findViewById(R.id.layout_settings); layout_home.setOnClickListener(myclick); layout_folders.setOnClickListener(myclick); layout_friends.setOnClickListener(myclick); layout_settings.setOnClickListener(myclick); image_home = (ImageView) findViewById(R.id.image_home); image_folders = (ImageView) findViewById(R.id.image_folders); image_friends = (ImageView) findViewById(R.id.image_friends); image_settings = (ImageView) findViewById(R.id.image_settings); text_home = (TextView) findViewById(R.id.text_home); text_folders = (TextView) findViewById(R.id.text_folders); text_friends = (TextView) findViewById(R.id.text_friends); text_settings = (TextView) findViewById(R.id.text_settings); }
@Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { // When the given tab is selected, switch to the corresponding page in // the ViewPager. mViewPager.setCurrentItem(tab.getPosition()); mViewPager.setOffscreenPageLimit(5); // setta il limite per non ricaricare i fragments }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.people_org_pager, container, false); TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout_org); tabLayout.addTab(tabLayout.newTab().setText("FOLLOWING")); tabLayout.addTab(tabLayout.newTab().setText("FOLOWERS")); tabLayout.addTab(tabLayout.newTab().setText("ORGANIZATIONS")); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); final ViewPager viewPager = (ViewPager) view.findViewById(R.id.pager_org); final PagerOrgAdapter adapter = new PagerOrgAdapter(getActivity().getSupportFragmentManager(), tabLayout.getTabCount()); viewPager.setAdapter(adapter); viewPager.setOffscreenPageLimit(2); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) {} }); return view; }
private void setUpPagerAndTabs() { pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new StreamMediaPlayerPagerAdapter(StreamVideoActivity.this, getSupportFragmentManager()); pager.setAdapter(pagerAdapter); pager.setOffscreenPageLimit(2); tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.setTabsFromPagerAdapter(pagerAdapter); tabLayout.setupWithViewPager(pager); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { pager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { if (tab.getPosition() == 0) { pagerAdapter.mFragment.hideAll(); } } @Override public void onTabReselected(TabLayout.Tab tab) {} }); }
public void initView() { if (adapter == null) { adapter = new ItemFragmentPagerAdapter(this.getSupportFragmentManager(), fragmentList); viewpager.setOffscreenPageLimit(4); viewpager.setAdapter(adapter); } else { adapter.notifyDataSetChanged(); } rela1.setOnClickListener(this); rela2.setOnClickListener(this); rela3.setOnClickListener(this); setTabSelectState(); viewpager.setCurrentItem(0); title.setText("下拉刷新"); viewpager.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int i, float v, int i2) {} @Override public void onPageSelected(int i) { tabIndex = i; setTabSelectState(); } @Override public void onPageScrollStateChanged(int i) {} }); }
private void setupChildren() { topbar = new LinearLayout(getContext()); topbar.setOrientation(LinearLayout.HORIZONTAL); topbar.setClipChildren(false); topbar.setClipToPadding(false); addView(topbar, new LayoutParams(1)); buttonPast.setScaleType(ImageView.ScaleType.CENTER_INSIDE); buttonPast.setImageResource(R.drawable.mcv_action_previous); topbar.addView(buttonPast, new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1)); title.setGravity(Gravity.CENTER); topbar.addView( title, new LinearLayout.LayoutParams( 0, LayoutParams.MATCH_PARENT, MonthView.DEFAULT_DAYS_IN_WEEK - 2)); buttonFuture.setScaleType(ImageView.ScaleType.CENTER_INSIDE); buttonFuture.setImageResource(R.drawable.mcv_action_next); topbar.addView(buttonFuture, new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1)); pager.setId(R.id.mcv_pager); pager.setOffscreenPageLimit(1); addView(pager, new LayoutParams(MonthView.DEFAULT_MONTH_TILE_HEIGHT)); }
public void initContentView() { // 底部 footer = (CustomRadioGroup) findViewById(R.id.main_footer); footer.setBackgroundColor(Color.parseColor("#94d8b6")); for (int i = 0; i < menu.subMenus.size(); i++) { footer.addItem( menu.subMenus.get(i).iconNormal, menu.subMenus.get(i).iconPressed, menu.subMenus.get(i).name); } // 主体 body = (ViewPager) findViewById(R.id.main_body); final MainBodyPageChangeListener bodyChangeListener = new MainBodyPageChangeListener(footer); body.setOnPageChangeListener(bodyChangeListener); initFragments(); body.setOffscreenPageLimit(4); MainPagerAdapter mAdapetr = new MainPagerAdapter(getChildFragmentManager(), fragments); body.setAdapter(mAdapetr); body.setCurrentItem(0); footer.setCheckedIndex(body.getCurrentItem()); footer.setOnItemChangedListener( new CustomRadioGroup.OnItemChangedListener() { public void onItemChanged() { body.setCurrentItem(footer.getCheckedIndex(), false); } }); // footer.setItemNewsCount(1, 10);// 设置消息数量 }
/** Setting the CarouselView with data */ private void setCarouselView() { // Getting the number of services discovered PAGES = ProfileScanningFragment.gattServiceData.size(); FIRST_PAGE = PAGES * LOOPS / 2; // Setting the adapter adapter = new CarouselPagerAdapter( getActivity(), ProfileControlFragment.this, getActivity().getSupportFragmentManager(), ProfileScanningFragment.gattServiceData); pager.setAdapter(adapter); pager.setOnPageChangeListener(adapter); // Set current item to the middle page so we can fling to both // directions left and right pager.setCurrentItem(FIRST_PAGE); // Necessary or the pager will only have one extra page to show // make this at least however many pages you can see pager.setOffscreenPageLimit(3); Toast.makeText( getActivity(), getResources().getString(R.string.toast_swipe_profiles), Toast.LENGTH_SHORT) .show(); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_my_tba, container, false); mViewPager = (ViewPager) v.findViewById(R.id.my_tba_pager); // Make this ridiculously big mViewPager.setOffscreenPageLimit(50); mViewPager.setPageMargin(Utilities.getPixelsFromDp(getActivity(), 16)); mTabs = (SlidingTabs) v.findViewById(R.id.my_tba_tabs); ViewCompat.setElevation(mTabs, getResources().getDimension(R.dimen.toolbar_elevation)); /** * Fix for really strange bug. Menu bar items wouldn't appear only when navigated to from * 'Events' in the nav drawer Bug is some derivation of this: * https://code.google.com/p/android/issues/detail?id=29472 So set the view pager's adapter in * another thread to avoid a race condition, or something. */ mViewPager.post( () -> { mViewPager.setAdapter(new MyTBAFragmentPagerAdapter(getChildFragmentManager())); mTabs.setViewPager(mViewPager); }); return v; }
@Override public void onNewIntent(Intent intent) { if (D) Log.e(TAG, "+++ NEW INTENT +++"); // Set up the window layout requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title); // Set up the custom title mTitle = (TextView) findViewById(R.id.title_left_text); mTitle.setText(R.string.right_title); mTitle = (TextView) findViewById(R.id.title_right_text); Intent intent1 = getIntent(); TCPAddress = intent1.getStringExtra("TCPAddress"); AndroiDAQTCPAdapter adapter = new AndroiDAQTCPAdapter(this); pager = (ViewPager) findViewById(R.id.viewpager); pager.setOffscreenPageLimit(6); indicator = (TitlePageIndicator) findViewById(R.id.indicator); pager.setAdapter(adapter); indicator.setViewPager(pager); mWaveform = (WaveFormView) findViewById(R.id.WaveformArea); // indicator.setOnPageChangeListener(this); }
@Override public void onCreate(Context context, final IView view) { ViewPager viewPager = view.get(R.id.state_vp); viewPager.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { ((StateView) view).setState(position); } @Override public void onPageScrollStateChanged(int state) {} }); ((StateView) view).setOnclickListener(viewPager); TrackerNewFragment newFragment = new TrackerNewFragment(); TrackerNewFragment myFragment = new TrackerNewFragment(); TrackerNewFragment advFragment = new TrackerNewFragment(); List<Fragment> list = new ArrayList<Fragment>(); list.add(myFragment); list.add(advFragment); list.add(newFragment); FragmentAdapter mFragmentAdapter = new FragmentAdapter(fragmentManager, list); viewPager.setAdapter(mFragmentAdapter); viewPager.setCurrentItem(0); viewPager.setOffscreenPageLimit(list.size()); }
private void initComponent() { LayoutInflater inflater = getActivity().getLayoutInflater(); mMainView = inflater.inflate(R.layout.fragment_main, null, false); viewPager = (ViewPager) mMainView.findViewById(R.id.viewpager); fragmentList = new ArrayList<Fragment>(); fragmentList.add(new MyFragment(null)); fragmentList.add(new FindFragment()); fragmentList.add(new SearchFragment()); tabButton = new RadioButton[fragmentList.size()]; tabButton[0] = (RadioButton) mMainView.findViewById(R.id.tab_my); tabButton[1] = (RadioButton) mMainView.findViewById(R.id.tab_find); tabButton[2] = (RadioButton) mMainView.findViewById(R.id.tab_search); group = (RadioGroup) mMainView.findViewById(R.id.tab); group.setOnCheckedChangeListener(new TabOnCheckedChangeListener()); viewPager.setAdapter(new TabFragmentPagerAdapter(getFragmentManager())); viewPager.setCurrentItem(0); // 设置viewpager的缓存页面 viewPager.setOffscreenPageLimit(fragmentList.size()); viewPager.setOnPageChangeListener(new TabOnPageChangeListener()); // viewPager.setBackgroundResource(R.drawable.skin_def); setTabButtonBackground(TAB_INDEX); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 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(); // } // }); pagerTab = (PagerSlidingTabStrip) findViewById(R.id.pager_tabs); viewPager = (ViewPager) findViewById(R.id.view_pager); viewPager.setOffscreenPageLimit(3); viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager())); pagerTab.setViewPager(viewPager); pagerTab.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { if (position == 0) {} } @Override public void onPageScrollStateChanged(int state) {} }); }
private void initView() { mViewPager = (ViewPager) this.findViewById(R.id.viewpager); mPageNum = (TextView) this.findViewById(R.id.page_num); mEditText = (EditText) this.findViewById(R.id.edit_text); mButton = (Button) this.findViewById(R.id.button); mButton.setOnClickListener(this); List<Fragment> fragments = new ArrayList<Fragment>(); Fragment fragment1 = MyOneFragment.newInstance(); Fragment fragment2 = MyTwoFragment.newInstance(); Fragment fragment3 = MyThreeFragment.newInstance(); Fragment fragment4 = MyFourFragment.newInstance(); Fragment fragment5 = MyFiveFragment.newInstance(); fragments.add(fragment1); fragments.add(fragment2); fragments.add(fragment3); fragments.add(fragment4); fragments.add(fragment5); mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragments); mViewPager.setAdapter(mMyFragmentPagerAdapter); mViewPager.setPageTransformer(true, new FragmentTransformer()); // 设置页面变换监听,对每个页面的变化都有一个变换的监听 mViewPager.addOnPageChangeListener(new OnMyPageChangeListener()); // 页面变化监听 mViewPager.setOffscreenPageLimit(2); // 设置缓存页面数。当前页,左右两边(单边)最大缓存页面数。 // mViewPager.setOnScrollChangeListener(new // OnMyScrollChangeListener());//滚动状态监听,minSdkVersion:23 // mViewPager.getCurrentItem();//获取当前显示页索引 // mViewPager.getOffscreenPageLimit();//获取缓存页面数 // mViewPager.onSaveInstanceState(); // mViewPager.setPageTransformer(); setPageNum(0); // 设置显示首页 }
private final void i() { com.dianxinos.dxbs.R.id _tmp = ly.f; t = (MainTitle) findViewById(0x7f070018); com.dianxinos.dxbs.R.id _tmp1 = ly.f; u = findViewById(0x7f0700ed); n = a(p); Intent intent = getIntent(); if (intent != null) { n = intent.getIntExtra("tab", n); } q = new rf(this, this, e(), p); com.dianxinos.dxbs.R.id _tmp2 = ly.f; r = (ViewPager) findViewById(0x7f0700ef); r.setAdapter(q); r.setOnPageChangeListener(this); r.setOffscreenPageLimit(p.size()); com.dianxinos.dxbs.R.id _tmp3 = ly.f; s = (TitleIndicator) findViewById(0x7f0700ee); s.a(n, p, r); r.setCurrentItem(n); Message message = g(); if (message != null) { r.post(new re(this, message)); } }
/** Adds tabs below the action bar. */ private void addTabs() { viewPager = (ViewPager) findViewById(R.id.pager_main); actionBar = getActionBar(); mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(mAdapter); actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // temp fix, to make sure that PATHAlerts isn't refreshing all the time viewPager.setOffscreenPageLimit(4); // Adding Tabs for (String tab_name : tabs) { actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this)); } viewPager.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // on changing the page // make respected tab selected actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) {} @Override public void onPageScrollStateChanged(int arg0) {} }); }
private void init() { mTabTitles = new String[] {"FirstFragmetn", "SecondFragment", "ThirdFragment"}; firstFragment = new MLFirstFragment(); secondFragment = new MLSecondFragment(); thirdFragment = new MLThirdFragment(); mFragments = new Fragment[] {firstFragment, secondFragment, thirdFragment}; mAdapter = new MLFragmentPagerAdapter(getSupportFragmentManager(), mTabTitles, mFragments); mViewPager.setAdapter(mAdapter); mViewPager.setCurrentItem(0); // 设置 ViewPager 预加载数量 mViewPager.setOffscreenPageLimit(3); // 添加 ViewPager 页面改变监听 mViewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) {} @Override public void onPageScrollStateChanged(int state) {} }); mTabLayout.setupWithViewPager(mViewPager); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_viewpager); mViewPager = (ViewPager) findViewById(R.id.v_scroll); StickHeaderLayout shl_root = (StickHeaderLayout) findViewById(R.id.shl_root); mViewPager.setOffscreenPageLimit(4); manager = new StickHeaderViewPagerManager(shl_root, mViewPager); viewList = new ArrayList<ViewPagerBean>(); SimpleRecyclerView simpleRecyclerView = new SimpleRecyclerView(this); viewList.add( new ViewPagerBean(simpleRecyclerView, simpleRecyclerView.getPlaceHoderHeaderLayout())); SimpleScrollView simpleScrollView = new SimpleScrollView(this); viewList.add(new ViewPagerBean(simpleScrollView, simpleScrollView.getPlaceHoderHeaderLayout())); SimpleListView simpleListView = new SimpleListView(this); viewList.add(new ViewPagerBean(simpleListView, simpleListView.getPlaceHoderHeaderLayout())); SimpleWebView simpleWebView = new SimpleWebView(this); viewList.add(new ViewPagerBean(simpleWebView, simpleWebView.getPlaceHoderHeaderLayout())); mViewPager.setAdapter(pagerAdapter); initTabBar(); }
private void findview() { ballBtn = (Button) findViewById(R.id.found_bar_ball); friendBtn = (Button) findViewById(R.id.found_bar_friend); ballImg = (ImageView) findViewById(R.id.found_bar_ball_line); friendImg = (ImageView) findViewById(R.id.found_bar_friend_line); map = (ImageView) findViewById(R.id.found_map); ballBarLayout = (RelativeLayout) findViewById(R.id.found_bar_ball_layout); friendBarLaout = (RelativeLayout) findViewById(R.id.found_bar_friend_layout); viewPager = (ViewPager) findViewById(R.id.found_vPager); refreshBtn = (Button) findViewById(R.id.found_refresh); refreshBtn.setOnClickListener(this); ballBtn.setOnClickListener(this); friendBtn.setOnClickListener(this); map.setOnClickListener(this); viewPager.setOffscreenPageLimit(1); viewPager.setOnPageChangeListener(this); }