Java Code Examples for android.support.v4.view.ViewPager#setPageMargin()
The following examples show how to use
android.support.v4.view.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: PagerSlidingTabStripDemoActivity.java From android-open-project-demo with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demo); mPagerSlidingTabStrip = (PagerSlidingTabStrip) findViewById(R.id.tabs); mViewPager = (ViewPager) findViewById(R.id.pager); //设置页面之间的间隔,实际项目中应该用dip转px mViewPager.setPageMargin(10); initPageAdapter(); // mPagerSlidingTabStrip.setViewPager(mViewPager); }
Example 2
Source File: ViewpagerSlidingTabsActivity.java From UltimateAndroid with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.viewpager_sliding_tabs_activity); tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs); pager = (ViewPager) findViewById(R.id.pager); adapter = new MyPagerAdapter(getSupportFragmentManager()); pager.setAdapter(adapter); final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources() .getDisplayMetrics()); pager.setPageMargin(pageMargin); tabs.setViewPager(pager); changeColor(currentColor); }
Example 3
Source File: TeamActivity.java From Nimbus with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_team); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle("Teams"); viewPager = (ViewPager) findViewById(R.id.pager); viewPager2 = (ViewPager) findViewById(R.id.pager2); progressBar = (ProgressBar) findViewById(R.id.progressbar); message = (TextView) findViewById(R.id.message_textView); textcore = (TextView) findViewById(R.id.textcoreteam); textdept = (TextView) findViewById(R.id.textdeptteam); viewPager.setPageMargin(5); getAllCoreTeamList(); getAllTeamList(); }
Example 4
Source File: PageFragment.java From ChangeTabLayout with Apache License 2.0 | 6 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ViewPager mViewPager = (ViewPager) view.findViewById(R.id.vp); FragmentPagerItems pages = new FragmentPagerItems(getActivity()); final int page = FragmentPagerItem.getPosition(getArguments()); for (int i = 0; i < 5; i++) { Bundle bundle = new Bundle(); bundle.putInt("page", page); bundle.putInt("position", i); pages.add(FragmentPagerItem.of(String.valueOf(i), DemoFragment.class, bundle)); } FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(getChildFragmentManager(), pages); //Fragment嵌套Fragment时,要用getChildFragmentManager mViewPager.setAdapter(adapter); mViewPager.setOffscreenPageLimit(2); mViewPager.setPageMargin(30); final MainActivity mainActivity = (MainActivity) getActivity(); mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { mainActivity.pageScrolled(page, position, positionOffset); } }); }
Example 5
Source File: DetailActivity.java From atlas 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.base.R.dimen.padding_mini)); viewPager.setPageMarginDrawable(R.drawable.page_margin); }
Example 6
Source File: NowPlayingScreenPreferenceDialog.java From RetroMusicPlayer with GNU General Public License v3.0 | 6 votes |
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @SuppressLint("InflateParams") View view = LayoutInflater.from(getActivity()).inflate(R.layout.preference_dialog_now_playing_screen, null); ViewPager viewPager = ButterKnife.findById(view, R.id.now_playing_screen_view_pager); viewPager.setAdapter(new NowPlayingScreenAdapter(getActivity())); viewPager.addOnPageChangeListener(this); viewPager.setPageMargin((int) ViewUtil.convertDpToPixel(32, getResources())); viewPager.setCurrentItem(PreferenceUtil.getInstance(getActivity()).getNowPlayingScreen().ordinal()); return new MaterialDialog.Builder(getActivity()) .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 7
Source File: ViewpagerSlidingTabsActivity.java From UltimateAndroid with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.viewpager_sliding_tabs_activity); tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs); pager = (ViewPager) findViewById(R.id.pager); adapter = new MyPagerAdapter(getSupportFragmentManager()); pager.setAdapter(adapter); final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources() .getDisplayMetrics()); pager.setPageMargin(pageMargin); tabs.setViewPager(pager); changeColor(currentColor); }
Example 8
Source File: MusicMainActivity.java From mobile-manager-tool with MIT License | 6 votes |
/** * Initiate ViewPager and PagerAdapter */ public void initPager() { // Initiate PagerAdapter PagerAdapter mPagerAdapter = new PagerAdapter(getSupportFragmentManager()); mPagerAdapter.addFragment(new MusicAllListFragment()); mPagerAdapter.addFragment(new MusicOnlineFragment()); mPagerAdapter.addFragment(new MusicLoveListFragment()); // Initiate ViewPager ViewPager mViewPager = (ViewPager)findViewById(R.id.viewPager); mViewPager.setPageMargin(getResources().getInteger(R.integer.viewpager_margin_width)); mViewPager.setPageMarginDrawable(R.drawable.music_viewpager_margin); mViewPager.setOffscreenPageLimit(mPagerAdapter.getCount()); mViewPager.setAdapter(mPagerAdapter); // Tabs initScrollableTabs(mViewPager); }
Example 9
Source File: MusicLibrary.java From mobile-manager-tool with MIT License | 6 votes |
/** * Initiate ViewPager and PagerAdapter */ public void initPager() { // Initiate PagerAdapter PagerAdapter mPagerAdapter = new PagerAdapter(getSupportFragmentManager()); mPagerAdapter.addFragment(new MusicSongListFragment()); mPagerAdapter.addFragment(new MusicLoveListFragment()); // Initiate ViewPager ViewPager mViewPager = (ViewPager)findViewById(R.id.viewPager); mViewPager.setPageMargin(getResources().getInteger(R.integer.viewpager_margin_width)); mViewPager.setPageMarginDrawable(R.drawable.music_viewpager_margin); mViewPager.setOffscreenPageLimit(mPagerAdapter.getCount()); mViewPager.setAdapter(mPagerAdapter); //mViewPager.setCurrentItem(0); // Tabs initScrollableTabs(mViewPager); }
Example 10
Source File: NetworkMonitorActivity.java From bither-android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(R.anim.slide_in_right, 0); setContentView(R.layout.network_monitor_content); // final ActionBar actionBar = getSupportActionBar(); // actionBar.setDisplayHomeAsUpEnabled(true); final ViewPager pager = (ViewPager) findViewById(R.id.network_monitor_pager); final FragmentManager fm = getSupportFragmentManager(); if (pager != null) { final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.network_monitor_pager_tabs); pagerTabs.addTabLabels(R.string.network_monitor_peer_list_title, R.string.network_monitor_block_list_title); final PagerAdapter pagerAdapter = new PagerAdapter(fm); pager.setAdapter(pagerAdapter); pager.setOnPageChangeListener(pagerTabs); pager.setPageMargin(2); pager.setPageMarginDrawable(R.color.bg); peerListFragment = new PeerListFragment(); blockListFragment = new BlockListFragment(); } else { peerListFragment = (PeerListFragment) fm .findFragmentById(R.id.peer_list_fragment); blockListFragment = (BlockListFragment) fm .findFragmentById(R.id.block_list_fragment); } // flTitleBar = (FrameLayout) findViewById(R.id.fl_title_bar); ibtnBack = (ImageButton) findViewById(R.id.ibtn_back); ibtnBack.setOnClickListener(new IBackClickListener()); findViewById(R.id.ibtn_option).setOnClickListener(optionClick); }
Example 11
Source File: Gallery.java From Gallery with Apache License 2.0 | 5 votes |
public Gallery(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Gallery); Constant.GALLEY_SCALE_RATE = a.getFloat(R.styleable.Gallery_scaleP, Constant.GALLEY_SCALE_RATE); int galleryPadding = a.getDimensionPixelSize(R.styleable.Gallery_gallery_padding, 0); if (galleryPadding > 0) { galleryPaddingLeft = galleryPaddingRight = galleryPaddingTop = galleryPaddingBottom = galleryPadding; } else { galleryPaddingLeft = a.getDimensionPixelSize(R.styleable.Gallery_gallery_padding_left, galleryPaddingLeft); galleryPaddingRight = a.getDimensionPixelSize(R.styleable.Gallery_gallery_padding_right, galleryPaddingRight); galleryPaddingTop = a.getDimensionPixelSize(R.styleable.Gallery_gallery_padding_top, galleryPaddingTop); galleryPaddingBottom = a.getDimensionPixelSize(R.styleable.Gallery_gallery_padding_bottom, galleryPaddingBottom); } galleryCenterMargin = a.getDimensionPixelSize(R.styleable.Gallery_gallery_pics_space, galleryCenterMargin); a.recycle(); LayoutInflater.from(context).inflate(R.layout.gallery_layout, this, true); viewPager = (ViewPager) findViewById(R.id.view_pager); ((MarginLayoutParams)viewPager.getLayoutParams()).setMargins(galleryPaddingLeft, galleryPaddingTop, galleryPaddingRight, galleryPaddingBottom); viewPager.setPageMargin(galleryCenterMargin); viewPager.setOffscreenPageLimit(OFFSCREEN_PAGE_LIMIT); setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return viewPager.dispatchTouchEvent(event); } }); viewPager.addOnPageChangeListener(new PageChangeListener()); }
Example 12
Source File: ShowCoverFanartBrowser.java From Mizuu with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MizuuApplication.setupTheme(this); if (MizLib.hasLollipop()) getSupportActionBar().setElevation(0); getSupportActionBar().setDisplayHomeAsUpEnabled(true); tvdbId = getIntent().getExtras().getString("id"); mToolbarColor = getIntent().getExtras().getInt(IntentKeys.TOOLBAR_COLOR); mProgressBar = (ProgressBar) findViewById(R.id.progressbar); mProgressBar.setVisibility(View.VISIBLE); mViewPager = (ViewPager) findViewById(R.id.awesomepager); mViewPager.setOffscreenPageLimit(2); mViewPager.setPageMargin(MizLib.convertDpToPixels(this, 16)); mTabs = (PagerSlidingTabStrip) findViewById(R.id.tabs); mTabs.setVisibility(View.GONE); setupActionBarStuff(); if (savedInstanceState != null) { mViewPager.setCurrentItem(savedInstanceState.getInt("tab", 0)); } }
Example 13
Source File: TracksBrowser.java From mobile-manager-tool with MIT License | 5 votes |
/** * Initiate ViewPager and PagerAdapter */ private void initPager() { // Initiate PagerAdapter PagerAdapter mPagerAdapter = new PagerAdapter(getSupportFragmentManager()); if (ApolloUtils.isArtist(mimeType)) // Show all albums for an artist mPagerAdapter.addFragment(new ArtistAlbumsFragment(bundle)); // Show the tracks for an artist or album if(Playlists.CONTENT_TYPE.equals(mimeType)){ mPagerAdapter.addFragment(new PlaylistListFragment(bundle)); } else if(Genres.CONTENT_TYPE.equals(mimeType)){ mPagerAdapter.addFragment(new GenreListFragment(bundle)); } else if(ApolloUtils.isArtist(mimeType)){ mPagerAdapter.addFragment(new ArtistListFragment(bundle)); } else if(Audio.Albums.CONTENT_TYPE.equals(mimeType)){ mPagerAdapter.addFragment(new AlbumListFragment(bundle)); } // Set up ViewPager mViewPager = (ViewPager)findViewById(R.id.viewPager); mViewPager.setPageMargin(getResources().getInteger(R.integer.viewpager_margin_width)); mViewPager.setPageMarginDrawable(R.drawable.music_viewpager_margin); mViewPager.setOffscreenPageLimit(mPagerAdapter.getCount()); mViewPager.setAdapter(mPagerAdapter); mViewPager.setOnPageChangeListener(new PageListener()); }
Example 14
Source File: MainActivity.java From ChatKit with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new MainActivityPagerAdapter(this, getSupportFragmentManager())); pager.setPageMargin((int) getResources().getDimension(R.dimen.card_padding) / 4); pager.setOffscreenPageLimit(3); CircleIndicator indicator = (CircleIndicator) findViewById(R.id.indicator); indicator.setViewPager(pager); }
Example 15
Source File: MovieCoverFanartBrowser.java From Mizuu with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MizuuApplication.setupTheme(this); if (MizLib.hasLollipop()) getSupportActionBar().setElevation(0); mTmdbId = getIntent().getExtras().getString("tmdbId"); mCollectionId = getIntent().getExtras().getString("collectionId"); mToolbarColor = getIntent().getExtras().getInt(IntentKeys.TOOLBAR_COLOR); mTmdbApiKey = MizLib.getTmdbApiKey(this); mProgressBar = (ProgressBar) findViewById(R.id.progressbar); mProgressBar.setVisibility(View.VISIBLE); mViewPager = (ViewPager) findViewById(R.id.awesomepager); mViewPager.setOffscreenPageLimit(2); mViewPager.setPageMargin(MizLib.convertDpToPixels(this, 16)); mTabs = (PagerSlidingTabStrip) findViewById(R.id.tabs); mTabs.setVisibility(View.GONE); if (savedInstanceState != null) { mJson = savedInstanceState.getString("json", ""); mBaseUrl = savedInstanceState.getString("baseUrl"); mCollection = savedInstanceState.getString("collection"); setupActionBarStuff(); mViewPager.setCurrentItem(savedInstanceState.getInt("tab", 0)); } else { new MovieLoader(getApplicationContext()).execute(mTmdbId, mCollectionId); } }
Example 16
Source File: PagerExampleFragment.java From ShadowDrawable with MIT License | 5 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { viewPager = new ViewPager(getActivity()); viewPager.setClipChildren(false); viewPager.setClipToPadding(false); int padding = 12 * 3; viewPager.setPadding(padding, 0, padding, 0); viewPager.setPageMargin(-padding/2); return viewPager; }
Example 17
Source File: ImageViewer.java From Mizuu with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (MizLib.hasKitKat()) { setTheme(R.style.Mizuu_Theme_Translucent_FullScreen); } else { setTheme(R.style.Mizuu_Theme_Transparent_FullScreen); } ViewUtils.setupWindowFlagsForStatusbarOverlay(getWindow(), true); mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); ViewUtils.setProperToolbarSize(this, mToolbar); getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent_actionbar)); mBus = MizuuApplication.getBus(); mPortraitPhotos = getIntent().getBooleanExtra("portraitPhotos", true); mPhotos = getIntent().getStringArrayExtra("photos"); getSupportActionBar().setTitle((getIntent().getIntExtra("selectedIndex", 0) + 1) + " " + getString(R.string.of) + " " + mPhotos.length); mViewPager = (ViewPager) findViewById(R.id.awesomepager); mViewPager.setPageMargin(MizLib.convertDpToPixels(getApplicationContext(), 16)); mViewPager.setAdapter(new ActorPhotosAdapter(getSupportFragmentManager())); mViewPager.setOnPageChangeListener(new SimpleOnPageChangeListener() { @Override public void onPageSelected(int arg0) { getSupportActionBar().setTitle((arg0 + 1) + " " + getString(R.string.of) + " " + mPhotos.length); } }); mViewPager.setCurrentItem(getIntent().getIntExtra("selectedIndex", 0)); View decorView = getWindow().getDecorView(); decorView.setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { if (visibility == 0) { // The UI is visible due to user interaction - let's hide it again after three seconds mHandler.postDelayed(mHideSystemUiRunnable, 3000); } } }); }
Example 18
Source File: MainActivity.java From ResearchStack with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LogExt.d(getClass(), "onCreate"); setContentView(R.layout.rss_activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(true); if (pagerAdapter == null) { List<ActionItem> items = UiManager.getInstance().getMainTabBarItems(); pagerAdapter = new MainPagerAdapter(getSupportFragmentManager(), items); ViewPager viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(pagerAdapter); viewPager.setPageMargin(1); viewPager.setPageMarginDrawable(new ColorDrawable(Color.LTGRAY)); IconTabLayout tabLayout = (IconTabLayout) findViewById(R.id.tabLayout); tabLayout.setOnTabSelectedListener(new IconTabLayout.OnTabSelectedListenerAdapter() { @Override public void onTabSelected(TabLayout.Tab tab) { int index = tabLayout.getSelectedTabPosition(); viewPager.setCurrentItem(index); } }); for (ActionItem item : items) { tabLayout.addIconTab( item.getTitle(), item.getIcon(), items.indexOf(item) == 0, // need real logic for this (show badge) items.indexOf(item) == 0 ); } viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); } handleNotificationIntent(getIntent()); }
Example 19
Source File: PackageChooserPreference.java From Noyze with Apache License 2.0 | 4 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Force Holo Light since ?android:actionBarXX would use dark action bar Context layoutContext = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Light); LayoutInflater layoutInflater = LayoutInflater.from(layoutContext); View rootView = layoutInflater.inflate(R.layout.dialog_app_chooser, null); final ViewGroup tabWidget = (ViewGroup) rootView.findViewById(android.R.id.tabs); final ViewPager pager = (ViewPager) rootView.findViewById(R.id.pager); pager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics())); SimplePagedTabsHelper helper = new SimplePagedTabsHelper(layoutContext, tabWidget, pager); helper.addTab(R.string.title_apps, R.id.apps_list); // Set up apps mAppsList = (ListView) rootView.findViewById(R.id.apps_list); mAppsList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> listView, View view, int position, long itemId) { Log.i("PackageChooserPreference", "onItemClick(" + position + ")"); String appPackage = mAppsAdapter.getPackageName(position); Checkable checker = (Checkable) view; checker.setChecked(!checker.isChecked()); if (checker.isChecked()) { appPackages.add(appPackage); } else { appPackages.remove(appPackage); } mPreference.setPackages(appPackages); } }); tryBindLists(); return new AlertDialog.Builder(getActivity()) .setView(rootView) .setPositiveButton(android.R.string.ok, dismissListener) .create(); }
Example 20
Source File: MainActivity.java From Memory-capsule with Apache License 2.0 | 4 votes |
private void initViewPagercard(){//实现ViewPagerCard的生成 viewPagercard=(ViewPager)this.findViewById(R.id.viewpager_main); viewPagercard.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,24,getResources().getDisplayMetrics())); viewPagercard.setPageTransformer(false,new ScaleTransformer0(this)); }