Java Code Examples for androidx.viewpager.widget.ViewPager#setPageMargin()
The following examples show how to use
androidx.viewpager.widget.ViewPager#setPageMargin() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetailActivity.java From animation-samples with Apache License 2.0 | 6 votes |
private void setUpViewPager(ArrayList<Photo> photos) { viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(new DetailViewPagerAdapter(this, photos, sharedElementCallback)); viewPager.setCurrentItem(initialItem); viewPager.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if (viewPager.getChildCount() > 0) { viewPager.removeOnLayoutChangeListener(this); startPostponedEnterTransition(); } } }); viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.padding_mini)); viewPager.setPageMarginDrawable(R.drawable.page_margin); }
Example 2
Source File: NowPlayingScreenPreferenceDialog.java From Music-Player with GNU General Public License v3.0 | 6 votes |
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @SuppressLint("InflateParams") View view = LayoutInflater.from(getContext()).inflate(R.layout.preference_dialog_now_playing_screen, null); ViewPager viewPager = view.findViewById(R.id.now_playing_screen_view_pager); viewPager.setAdapter(new NowPlayingScreenAdapter(getContext())); viewPager.addOnPageChangeListener(this); viewPager.setPageMargin((int) ViewUtil.convertDpToPixel(32, getResources())); viewPager.setCurrentItem(PreferenceUtil.getInstance(getContext()).getNowPlayingScreen().ordinal()); InkPageIndicator pageIndicator = view.findViewById(R.id.page_indicator); pageIndicator.setViewPager(viewPager); pageIndicator.onPageSelected(viewPager.getCurrentItem()); return new MaterialDialog.Builder(getContext()) .title(R.string.pref_title_now_playing_screen_appearance) .positiveText(android.R.string.ok) .negativeText(android.R.string.cancel) .onAny(this) .customView(view, false) .build(); }
Example 3
Source File: DetailActivity.java From android-instant-apps with Apache License 2.0 | 6 votes |
private void setUpViewPager(ArrayList<Photo> photos) { viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(new DetailViewPagerAdapter(this, photos, sharedElementCallback)); viewPager.setCurrentItem(initialItem); viewPager.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if (viewPager.getChildCount() > 0) { viewPager.removeOnLayoutChangeListener(this); startPostponedEnterTransition(); } } }); viewPager.setPageMargin(getResources().getDimensionPixelSize( com.example.android.unsplash.R.dimen.padding_mini)); viewPager.setPageMarginDrawable(R.drawable.page_margin); }
Example 4
Source File: NowPlayingScreenPreferenceDialog.java From VinylMusicPlayer with GNU General Public License v3.0 | 6 votes |
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @SuppressLint("InflateParams") View view = LayoutInflater.from(getContext()).inflate(R.layout.preference_dialog_now_playing_screen, null); ViewPager viewPager = view.findViewById(R.id.now_playing_screen_view_pager); viewPager.setAdapter(new NowPlayingScreenAdapter(getContext())); viewPager.addOnPageChangeListener(this); viewPager.setPageMargin((int) ViewUtil.convertDpToPixel(32, getResources())); viewPager.setCurrentItem(PreferenceUtil.getInstance().getNowPlayingScreen().ordinal()); InkPageIndicator pageIndicator = view.findViewById(R.id.page_indicator); pageIndicator.setViewPager(viewPager); pageIndicator.onPageSelected(viewPager.getCurrentItem()); return new MaterialDialog.Builder(getContext()) .title(R.string.pref_title_now_playing_screen_appearance) .positiveText(android.R.string.ok) .negativeText(android.R.string.cancel) .onAny(this) .customView(view, false) .build(); }
Example 5
Source File: ClusterMapActivity.java From intra42 with Apache License 2.0 | 6 votes |
@Override public void setupViewPager(ViewPager viewPager) { ViewStatePagerAdapter adapter = new ViewStatePagerAdapter(getSupportFragmentManager()); adapter.addFragment(ClusterMapInfoFragment.newInstance(), getString(R.string.title_tab_cluster_map_info)); if (clusterData.clusters != null) for (Cluster i : clusterData.clusters) { adapter.addFragment(ClusterMapFragment.newInstance(i.hostPrefix), i.nameShort); } viewPager.setAdapter(adapter); viewPager.setPageMargin(20); viewPager.setPageMarginDrawable(R.color.textColorBlackPrimary); ((CustomViewPager) viewPager).setPagingEnabled(false); }
Example 6
Source File: VPAnim2Activity.java From AndroidAnimationExercise with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; setContentView(R.layout.activity_vpanim2); initDatas(); // Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); // setSupportActionBar(toolbar); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setPageMargin(20); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOffscreenPageLimit(3); mViewPager.setPageTransformer(true, new MyTranformer()); }
Example 7
Source File: NowPlayingScreenPreferenceDialog.java From Phonograph with GNU General Public License v3.0 | 6 votes |
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @SuppressLint("InflateParams") View view = LayoutInflater.from(getContext()).inflate(R.layout.preference_dialog_now_playing_screen, null); ViewPager viewPager = view.findViewById(R.id.now_playing_screen_view_pager); viewPager.setAdapter(new NowPlayingScreenAdapter(getContext())); viewPager.addOnPageChangeListener(this); viewPager.setPageMargin((int) ViewUtil.convertDpToPixel(32, getResources())); viewPager.setCurrentItem(PreferenceUtil.getInstance(getContext()).getNowPlayingScreen().ordinal()); InkPageIndicator pageIndicator = view.findViewById(R.id.page_indicator); pageIndicator.setViewPager(viewPager); pageIndicator.onPageSelected(viewPager.getCurrentItem()); return new MaterialDialog.Builder(getContext()) .title(R.string.pref_title_now_playing_screen_appearance) .positiveText(android.R.string.ok) .negativeText(android.R.string.cancel) .onAny(this) .customView(view, false) .build(); }
Example 8
Source File: RKListFragment.java From light-novel-library_Wenku8_Android with GNU General Public License v2.0 | 6 votes |
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Initialize the ViewPager and set an adapter ViewPager pager = getActivity().findViewById(R.id.rklist_pager); pager.setAdapter(new MyPagerAdapter(getChildFragmentManager())); // Bind the tabs to the ViewPager PagerSlidingTabStrip tabs = getActivity().findViewById(R.id.rklist_tabs); tabs.setViewPager(pager); // set page margin final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources() .getDisplayMetrics()); pager.setPageMargin(pageMargin); // set adapter MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager()); pager.setAdapter(adapter); }
Example 9
Source File: ItemPagerAdapter.java From materialistic with Apache License 2.0 | 5 votes |
public void bind(ViewPager viewPager, TabLayout tabLayout, FloatingActionButton navigationFab, FloatingActionButton genericFab) { viewPager.setPageMargin(viewPager.getResources().getDimensionPixelOffset(R.dimen.divider)); viewPager.setPageMarginDrawable(R.color.blackT12); viewPager.setOffscreenPageLimit(2); viewPager.setAdapter(this); tabLayout.setupWithViewPager(viewPager); mTabListener = new TabLayout.ViewPagerOnTabSelectedListener(viewPager) { @Override public void onTabSelected(TabLayout.Tab tab) { super.onTabSelected(tab); toggleFabs(viewPager.getCurrentItem() == 0, navigationFab, genericFab); Fragment fragment = getItem(viewPager.getCurrentItem()); if (fragment != null) { ((LazyLoadFragment) fragment).loadNow(); } } @Override public void onTabReselected(TabLayout.Tab tab) { Fragment fragment = getItem(viewPager.getCurrentItem()); if (fragment != null) { ((Scrollable) fragment).scrollToTop(); } } }; tabLayout.addOnTabSelectedListener(mTabListener); viewPager.setCurrentItem(mDefaultItem); toggleFabs(mDefaultItem == 0, navigationFab, genericFab); }