private void setupViewPager(ViewPager viewPager) { final ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); adapter.addFrag(((new PlaceholderFragment()).newInstance(0)), "Volume"); adapter.addFrag(((new PlaceholderFragment()).newInstance(1)), "Surface Area"); viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { adapter.getItem(position).setTransitionNameLollipop(); if (position > 0) adapter.getItem(position - 1).setTransitionNull(); else adapter.getItem(position + 1).setTransitionNull(); } @Override public void onPageSelected(int position) { adapter.getItem(position).setTransitionNameLollipop(); if (position > 0) adapter.getItem(position - 1).setTransitionNull(); else adapter.getItem(position + 1).setTransitionNull(); } @Override public void onPageScrollStateChanged(int state) {} }); viewPager.setAdapter(adapter); }
public void initViewPager(ViewPager viewPager) { // modified by maddog05 if (mViewPager == viewPager) return; if (mViewPager != null) viewPager.addOnPageChangeListener(this); if (viewPager.getAdapter() == null) throw new IllegalStateException("ViewPager doesn't have an adapter instance."); mViewPager = viewPager; mViewPager.addOnPageChangeListener(this); // finish modified circleCount = viewPager.getAdapter().getCount(); mCurrentDragPage = viewPager.getCurrentItem(); invalidate(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager); final ViewPager viewPager2 = (ViewPager) findViewById(R.id.viewPager2); viewPager.setAdapter(new MyPagerAdapter()); viewPager2.setAdapter(new MyPagerAdapter()); /** the current master viewPager */ AtomicReference<ViewPager> masterRef = new AtomicReference<>(); viewPager.addOnPageChangeListener( new ParallaxOnPageChangeListener(viewPager, viewPager2, masterRef)); viewPager2.addOnPageChangeListener( new ParallaxOnPageChangeListener(viewPager2, viewPager, masterRef)); }
private void setUpTabLayoutAndViewPager() { ContentPagerAdapter contentPagerAdapter = new ContentPagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(contentPagerAdapter); mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout)); mTabLayout.setTabsFromPagerAdapter(contentPagerAdapter); mTabLayout.setupWithViewPager(mViewPager); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mCoordinator = (CoordinatorLayout) findViewById(R.id.root_coordinator); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mToolbar = (Toolbar) findViewById(R.id.app_bar); setSupportActionBar(mToolbar); navigationView = (NavigationView) findViewById(R.id.navigation_drawer); navigationView.setItemIconTintList(null); navigationView.setNavigationItemSelectedListener(this); mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close); mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); mTabLayout = (TabLayout) findViewById(R.id.tab_layout); mAdapter = new TabPagerAdapter(this, getSupportFragmentManager()); mPager = (ViewPager) findViewById(R.id.view_pager); mPager.setAdapter(mAdapter); // Notice how the Tab Layout links with the Pager Adapter mTabLayout.setTabsFromPagerAdapter(mAdapter); // Notice how The Tab Layout adn View Pager object are linked mTabLayout.setupWithViewPager(mPager); mPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout)); if (getIntent() != null) { mPager.setCurrentItem(getIntent().getIntExtra("tab", 0)); } fragmentManager = getSupportFragmentManager(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // ButterKnife.bind(this); getSupportActionBar().hide(); final ViewPagerAdapter adap = new ViewPagerAdapter(getSupportFragmentManager()); viewpager.setAdapter(adap); viewpager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { updateTotal(position, PIC_LINKS.length); } @Override public void onPageScrollStateChanged(int state) {} }); updateTotal(0, PIC_LINKS.length); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_layout); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setTitle(R.string.empty); tabHost = (MaterialTabHost) findViewById(R.id.materialTabHost); viewPager = (ViewPager) findViewById(R.id.viewPager); MyPagerAdapter myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(myPagerAdapter); viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { tabHost.setSelectedNavigationItem(position); } @Override public void onPageScrollStateChanged(int state) {} }); for (int i = 0; i < myPagerAdapter.getCount(); i++) { tabHost.addTab(tabHost.newTab().setText(myPagerAdapter.getPageTitle(i)).setTabListener(this)); } /* Intent intent = new Intent(this, BackgroundCallsService.class); startService(intent);*/ }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_touristic_point); // Toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitleTextColor(Color.WHITE); toolbar.setSubtitleTextColor(Color.WHITE); setSupportActionBar(toolbar); // Create the adapter that will return a fragment for each of the sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.addOnPageChangeListener(this); // Tabs TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); // Recebendo dados da outra activity Intent intent = getIntent(); int id = intent.getExtras().getInt("id"); touristicPoint = DatabaseDAO.getInstance().getTouristicPointByID(id); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fresco.initialize(this); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); viewPager = (ViewPager) findViewById(R.id.vp_img); viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int i, float v, int i1) {} @Override public void onPageSelected(int i) { Toast.makeText(MainActivity.this, "" + i, Toast.LENGTH_SHORT).show(); } @Override public void onPageScrollStateChanged(int i) {} }); viewPager.setAdapter( new PagerAdapter() { @Override public Object instantiateItem(ViewGroup container, int position) { SimpleDraweeView mDraweeViewe = new SimpleDraweeView(MainActivity.this); // ImageView imgView = (ImageView) // View.inflate(getApplicationContext(),R.layout.layout_imgview, null); /*GenericDraweeHierarchy hierarchy = mDraweeViewe.getHierarchy(); hierarchy.setPlaceholderImage(imgIds[position]);*/ mDraweeViewe.setScaleType(ImageView.ScaleType.CENTER_CROP); mDraweeViewe.setAspectRatio(1f); Uri imgUri = Uri.parse(imgUrls[position]); mDraweeViewe.setImageURI(imgUri); container.addView(mDraweeViewe); ivList.add(mDraweeViewe); return mDraweeViewe; } @Override public int getItemPosition(Object object) { return super.getItemPosition(object); } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView(ivList.get(position)); } @Override public int getCount() { return imgUrls.length; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } }); }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_speelveld); // Intent intent = getIntent(); // deelneemGegevens = intent.getStringArrayExtra("strings"); // spelerLijst[1] = deelneemGegevens[0]; ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager); adapter = new ImageAdapter(this); viewPager.setAdapter(adapter); setNaam(); // Een listener voor het ophalen van de geselceteerde kaart viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int cardNumber) { selectedCard = cardNumber; huidigeKaart(); } @Override public void onPageScrollStateChanged(int state) {} }); getKaartenDatabase(); }
public void setUpWithViewPager(final ViewPager viewPager) { if (viewPager != null) { viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) { mCurrentIndex = viewPager.getCurrentItem(); mNewIndex = position; mPageOffset = positionOffset; postInvalidate(); } @Override public void onPageSelected(int position) {} @Override public void onPageScrollStateChanged(int state) {} }); if (viewPager.getAdapter() != null) { count = viewPager.getAdapter().getCount(); } } }
private void setUI() { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { toolbar.setTitleTextColor(getResources().getColor(R.color.white)); } TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText(R.string.current_task)); // создание вкладок tabLayout.addTab(tabLayout.newTab().setText(R.string.done_task)); // создание вкладок final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); TabAdapter tabAdapter = new TabAdapter(fragmentManager, 2); // 2 - кол-во вкладок viewPager.setAdapter(tabAdapter); 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) {} }); }
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_exam217); // 테이블레이아웃 mTabLayout = (TabLayout) findViewById(R.id.tablayout); mViewPager = (ViewPager) findViewById(R.id.viewpager); // 탭설정하기 mTabLayout.addTab(mTabLayout.newTab().setText("플레이어")); mTabLayout.addTab(mTabLayout.newTab().setText("아티스트")); mTabLayout.addTab(mTabLayout.newTab().setText("노래")); // view에 들어갈 데이터를 준비해야 한다. mData = new ArrayList<>(); mData.add(new ArtistFragment()); // Adapter 준비 mAdapter = new MyPagerAdater(getSupportFragmentManager(), mData); // view에 어뎁터 붙이기 mViewPager.setAdapter(mAdapter); // 탭레이아웃 붙히기 (뷰페이저와 탭레이아웃 연결 하기) mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout)); }
@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; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_route); viewPager = (ViewPager) findViewById(R.id.rviewpager); setupViewPager(viewPager); tabLayout = (TabLayout) findViewById(R.id.rtabs); tabLayout.setupWithViewPager(viewPager); setupTabIcons(); viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { // Not needed. @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} // This is when the user pushes one of the tabs. @Override public void onPageSelected(int position) { if (position == 0) { } else if (position == 1) { } else if (position == 2) { } } // Just for the future. @Override public void onPageScrollStateChanged(int state) {} }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_article_detail); getLoaderManager().initLoader(0, null, this); mPagerAdapter = new MyPagerAdapter(getFragmentManager()); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mPagerAdapter); mPager.setPageMargin( (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics())); mPager.setPageMarginDrawable(new ColorDrawable(0x22000000)); mPager.addOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { if (mCursor != null) { mCursor.moveToPosition(position); } mSelectedItemId = mCursor.getLong(ArticleLoader.Query._ID); } }); if (savedInstanceState == null) { if (getIntent() != null && getIntent().getData() != null) { mStartId = ItemsContract.Items.getItemId(getIntent().getData()); mSelectedItemId = mStartId; } } }
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); // 设置显示首页 }
/** * 设置Adapter * * @param adapter */ public void setAdapter(PagerAdapter adapter) { mViewPager.setAdapter(adapter); mViewPager.addOnPageChangeListener(this); mAdapter = adapter; dataSetChanged(); adapter.registerDataSetObserver(new JPagerObserver()); }
/** Add viewpager listener */ private void viewPagerAddListener() { viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { boolean scrolling = false; @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (scrolling == false) { currentOpenedTab = position; updateListFragmentView(position); System.out.println("f****d it " + position); if (currentOpenedTab == position) scrolling = false; } } @Override public void onPageSelected(int position) { if (currentOpenedTab != position) { scrolling = true; currentOpenedTab = position; System.out.println(position + " positioned"); updateListFragmentView(position); } } @Override public void onPageScrollStateChanged(int state) {} }); }
private void initViewPager() { seekBar.setMax(viewPager.getAdapter().getCount() - 1); seekBar.setOnSeekBarChangeListener(this); seekBar.setProgress(viewPager.getCurrentItem()); viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { seekBar.setProgress(position); updateCurPos(position, seekBar.getMax()); } @Override public void onPageScrollStateChanged(int state) {} }); viewPager.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) {} }); updateCurPos(seekBar.getProgress(), seekBar.getMax()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Utils.showUpdateDialogIfNecessary(this); setContentView(R.layout.activity_repcast); if (savedInstanceState == null) { mPagerAdapter = new RepcastPageAdapter(getSupportFragmentManager(), this, getApplicationContext()); } else { mBackSelectFileFragments.addAll( Arrays.asList(savedInstanceState.getParcelableArray(INSTANCE_STATE_BACK_STACK_FILES))); mBackTorrentFragments.addAll( Arrays.asList(savedInstanceState.getParcelableArray(INSTANCE_STATE_BACK_STACK_TORRENTS))); mPagerAdapter = new RepcastPageAdapter( getSupportFragmentManager(), getApplicationContext(), (JsonDirectory.JsonFileDir) mBackSelectFileFragments.peek(), (JsonTorrent.JsonTorrentResult) mBackTorrentFragments.peek()); } TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); mViewPager = (ViewPager) findViewById(R.id.viewpager); mViewPager.setAdapter(mPagerAdapter); mViewPager.setCurrentItem(RepcastPageAdapter.FILE_INDEX); mViewPager.addOnPageChangeListener(this); completeOnCreate(savedInstanceState, true); tabLayout.setupWithViewPager(mViewPager); }
private void init() { mSwipeBackLayout.addSwipeListener(this); mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT); PageAdapter adapter = new PageAdapter(getSupportFragmentManager()); mViewPager.setAdapter(adapter); mViewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { Log.d(TAG, "position->" + position); if (position == 0) { getSwipeBackLayout().setEdgeSize(Utils.dp2px(200)); } else { getSwipeBackLayout().setEdgeSize(0); } } @Override public void onPageSelected(int position) {} @Override public void onPageScrollStateChanged(int state) {} }); // mViewPager.setPageTransformer(false, new PageTransformer()); }
@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 public void onFinishInflate() { super.onFinishInflate(); if (getChildCount() != 3) { throw new IllegalStateException(BGAStickyNavLayout.class.getSimpleName() + "必须有且只有三个子控件"); } mHeaderView = getChildAt(0); mNavView = getChildAt(1); mContentView = getChildAt(2); if (mContentView instanceof AbsListView) { mDirectAbsListView = (AbsListView) mContentView; mDirectAbsListView.setOnScrollListener(mLvOnScrollListener); } else if (mContentView instanceof RecyclerView) { mDirectRecyclerView = (RecyclerView) mContentView; mDirectRecyclerView.addOnScrollListener(mRvOnScrollListener); } else if (mContentView instanceof ScrollView) { mDirectScrollView = (ScrollView) mContentView; } else if (mContentView instanceof WebView) { mDirectWebView = (WebView) mContentView; } else if (mContentView instanceof ViewPager) { mDirectViewPager = (ViewPager) mContentView; mDirectViewPager.addOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { regetNestedContentView(); } }); } else { mDirectNormalView = mContentView; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); CalligraphyConfig.initDefault( new CalligraphyConfig.Builder() .setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf") .setFontAttrId(R.attr.fontPath) .build()); Initializetabs(); viewpager = (ViewPager) findViewById(R.id.viewpager); viewpager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager())); viewpager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { setTabs(position); } @Override public void onPageScrollStateChanged(int state) {} }); }
private void initView() { mCurrentTabIndex = 0; mTabTitles = new String[] { mActivity.getResources().getString(R.string.ml_chat), mActivity.getResources().getString(R.string.ml_contacts), mActivity.getResources().getString(R.string.ml_test) }; mContactsFragment = MLContactsFragment.newInstance(); mConversationFragment = MLConversationsFragment.newInstance(); mTestFragment = MLTestFragment.newInstance(); mFragments = new Fragment[] {mConversationFragment, mContactsFragment, mTestFragment}; MLViewPagerAdapter adapter = new MLViewPagerAdapter(getSupportFragmentManager(), mFragments, mTabTitles); mViewPager.setAdapter(adapter); mViewPager.setCurrentItem(mCurrentTabIndex); mViewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { getToolbar().setTitle(mTabTitles[position]); } @Override public void onPageScrollStateChanged(int state) {} }); mTabLayout.setupWithViewPager(mViewPager); }
@Override public void onResume() { super.onResume(); mViewPager.addOnPageChangeListener(mOnPageChangeListener); mViewPager.addOnAdapterChangeListener(mOnAdapterChangeListener); LocalBroadcastManager.getInstance(this).registerReceiver(mResultsReceiver, mIntentFilter); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main3); ButterKnife.bind(this); initWindow(); initView(); setAllClick(); pager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled( int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { select1.setImageResource(R.drawable.page_indicator_unfocused); select2.setImageResource(R.drawable.page_indicator_unfocused); if (position == 0) { select1.setImageResource(R.drawable.page_indicator_focused); } else { select2.setImageResource(R.drawable.page_indicator_focused); } } @Override public void onPageScrollStateChanged(int state) {} }); }
private void initView() { List<View> imageViews = new ArrayList<View>(); for (String img : imgs) { ImageView imageView = new ImageView(this); ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); imageView.setLayoutParams(lp); imageViews.add(imageView); } newsImgs.setAdapter(new _NewsImagesAdapter(imageViews, imgs)); allIndex.setText(imgs.length + ""); newsImgs.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { nowPager = position; index.setText((position + 1) + ""); description.setText(descriptions[position]); } @Override public void onPageSelected(int position) {} @Override public void onPageScrollStateChanged(int state) {} }); goback.setOnClickListener(this); share.setOnClickListener(this); forwarding.setOnClickListener(this); }