本文整理汇总了Java中android.support.v4.view.ViewPager.setPageMargin方法的典型用法代码示例。如果您正苦于以下问题:Java ViewPager.setPageMargin方法的具体用法?Java ViewPager.setPageMargin怎么用?Java ViewPager.setPageMargin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.ViewPager
的用法示例。
在下文中一共展示了ViewPager.setPageMargin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preview);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("");
Bundle bundle = getIntent().getExtras();
position = bundle.getInt("position", 0);
// 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.setAdapter(mSectionsPagerAdapter);
mViewPager.setCurrentItem(position);
mViewPager.setPageMargin(UiUtil.convertDpToPx(this, 16));
}
示例2: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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);
}
示例3: onCreateDialog
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@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 = ButterKnife.findById(view, 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 = ButterKnife.findById(view, R.id.page_indicator);
pageIndicator.setViewPager(viewPager);
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();
}
示例4: onCreateDialog
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@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();
}
示例5: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@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);
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();
}
示例6: onViewCreated
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@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);
}
});
}
示例7: setupViewPager
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
private void setupViewPager(final ViewPager viewPager)
{
adapterPager.add("tab a", new FragmentIntroA());
adapterPager.add("tab 2", new FragmentIntroB());
adapterPager.add("tab 3", new FragmentIntroC());
viewPager.setAdapter(adapterPager);
viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.page_margin));
indicator.setFinalStateViewPager(ActivityIntro.this, viewPager);
}
示例8: onCreateView
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
public View onCreateView(
final LayoutInflater inflater,
final @Nullable ViewGroup container,
final @Nullable Bundle savedInstanceState) {
pager = (ViewPager) inflater.inflate(R.layout.fragment_attachment_pager, container, false);
pager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.grid_spacer1));
pager.setAdapter(adapter);
return pager;
}
开发者ID:PacktPublishing,项目名称:Hands-On-Android-UI-Development,代码行数:12,代码来源:AttachmentPagerFragment.java
示例9: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.network_monitor_content);
final ViewPager pager = (ViewPager) findViewById(R.id.network_monitor_pager);
final FragmentManager fm = getFragmentManager();
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_less_bright);
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);
}
}
示例10: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.address_book_content);
final FragmentManager fragmentManager = getFragmentManager();
walletAddressesFragment = (WalletAddressesFragment) fragmentManager.findFragmentByTag(TAG_LEFT);
sendingAddressesFragment = (SendingAddressesFragment) fragmentManager.findFragmentByTag(TAG_RIGHT);
final FragmentTransaction removal = fragmentManager.beginTransaction();
if (walletAddressesFragment == null)
walletAddressesFragment = new WalletAddressesFragment();
else
removal.remove(walletAddressesFragment);
if (sendingAddressesFragment == null)
sendingAddressesFragment = new SendingAddressesFragment();
else
removal.remove(sendingAddressesFragment);
if (!removal.isEmpty()) {
removal.commit();
fragmentManager.executePendingTransactions();
}
final ViewPager pager = (ViewPager) findViewById(R.id.address_book_pager);
if (pager != null) {
pager.setAdapter(
new TwoFragmentAdapter(fragmentManager, walletAddressesFragment, sendingAddressesFragment));
final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.address_book_pager_tabs);
pagerTabs.addTabLabels(R.string.address_book_list_receiving_title,
R.string.address_book_list_sending_title);
pager.setOnPageChangeListener(pagerTabs);
final int position = 1;
pager.setCurrentItem(position);
pager.setPageMargin(2);
pager.setPageMarginDrawable(R.color.bg_less_bright);
pagerTabs.onPageSelected(position);
pagerTabs.onPageScrolled(position, 0, 0);
} else {
fragmentManager.beginTransaction().add(R.id.wallet_addresses_fragment, walletAddressesFragment, TAG_LEFT)
.add(R.id.sending_addresses_fragment, sendingAddressesFragment, TAG_RIGHT).commit();
}
updateFragments();
}
示例11: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@TargetApi(VERSION_CODES.HONEYCOMB)
@Override
public void onCreate(Bundle savedInstanceState) {
if (BuildConfig.DEBUG) {
Utils.enableStrictMode();
}
super.onCreate(savedInstanceState);
setContentView(R.layout.image_detail_pager);
// Fetch screen height and width, to use as our max size when loading images as this
// activity runs full screen
final DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
final int height = displayMetrics.heightPixels;
final int width = displayMetrics.widthPixels;
// For this sample we'll use half of the longest width to resize our images. As the
// image scaling ensures the image is larger than this, we should be left with a
// resolution that is appropriate for both portrait and landscape. For best image quality
// we shouldn't divide by 2, but this will use more memory and require a larger memory
// cache.
final int longest = (height > width ? height : width) / 2;
ImageCache.ImageCacheParams cacheParams =
new ImageCache.ImageCacheParams(this, IMAGE_CACHE_DIR);
cacheParams.setMemCacheSizePercent(0.25f); // Set memory cache to 25% of app memory
// The ImageFetcher takes care of loading images into our ImageView children asynchronously
mImageFetcher = new ImageFetcher(this, longest);
mImageFetcher.addImageCache(getSupportFragmentManager(), cacheParams);
mImageFetcher.setImageFadeIn(false);
// Set up ViewPager and backing adapter
mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), Images.imageUrls.length);
mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mPager.setPageMargin((int) getResources().getDimension(R.dimen.horizontal_page_margin));
mPager.setOffscreenPageLimit(2);
// Set up activity to go full screen
getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);
// Enable some additional newer visibility and ActionBar features to create a more
// immersive photo viewing experience
if (Utils.hasHoneycomb()) {
final ActionBar actionBar = getActionBar();
// Hide title text and set home as up
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
// Hide and show the ActionBar as the visibility changes
mPager.setOnSystemUiVisibilityChangeListener(
new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int vis) {
if ((vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0) {
actionBar.hide();
} else {
actionBar.show();
}
}
});
// Start low profile mode and hide ActionBar
mPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
actionBar.hide();
}
// Set the current item based on the extra passed in to this activity
final int extraCurrentItem = getIntent().getIntExtra(EXTRA_IMAGE, -1);
if (extraCurrentItem != -1) {
mPager.setCurrentItem(extraCurrentItem);
}
}
示例12: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
backgroundThread = new HandlerThread("BackgroundThumbnailHandlerThread");
backgroundThread.start();
backgroundHandler = new Handler(backgroundThread.getLooper());
setContentView(R.layout.flickr_search_activity);
searching = findViewById(R.id.searching);
searchLoading = findViewById(R.id.search_loading);
searchTerm = (TextView) findViewById(R.id.search_term);
Resources res = getResources();
ViewPager pager = (ViewPager) findViewById(R.id.view_pager);
pager.setPageMargin(res.getDimensionPixelOffset(R.dimen.page_margin));
pager.setAdapter(new FlickrPagerAdapter(getSupportFragmentManager()));
Api.get(this).registerSearchListener(queryListener);
if (savedInstanceState != null) {
Query savedQuery = savedInstanceState.getParcelable(STATE_QUERY);
if (savedQuery != null) {
executeQuery(savedQuery);
}
} else {
executeQuery(RecentQuery.get());
}
int smallGridSize = res.getDimensionPixelSize(R.dimen.small_photo_side);
int mediumGridSize = res.getDimensionPixelSize(R.dimen.medium_photo_side);
int listHeightSize = res.getDimensionPixelSize(R.dimen.flickr_list_item_height);
int screenWidth = getScreenWidth();
if (savedInstanceState == null) {
// Weight values determined experimentally by measuring the number of incurred GCs while
// scrolling through the various photo grids/lists.
GlideApp.get(this).preFillBitmapPool(
new PreFillType.Builder(smallGridSize).setWeight(1),
new PreFillType.Builder(mediumGridSize).setWeight(1),
new PreFillType.Builder(screenWidth / 2, listHeightSize).setWeight(6));
}
}
示例13: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
backgroundThread = new HandlerThread("BackgroundThumbnailHandlerThread");
backgroundThread.start();
backgroundHandler = new Handler(backgroundThread.getLooper());
setContentView(R.layout.flickr_search_activity);
searching = findViewById(R.id.searching);
searchLoading = findViewById(R.id.search_loading);
searchTerm = (TextView) findViewById(R.id.search_term);
Resources res = getResources();
ViewPager pager = (ViewPager) findViewById(R.id.view_pager);
pager.setPageMargin(res.getDimensionPixelOffset(R.dimen.page_margin));
pager.setAdapter(new FlickrPagerAdapter(getSupportFragmentManager()));
Api.get(this).registerSearchListener(queryListener);
if (savedInstanceState != null) {
Query savedQuery = savedInstanceState.getParcelable(STATE_QUERY);
if (savedQuery != null) {
executeQuery(savedQuery);
}
} else {
executeQuery(DEFAULT_QUERY);
}
int smallGridSize = res.getDimensionPixelSize(R.dimen.small_photo_side);
int mediumGridSize = res.getDimensionPixelSize(R.dimen.medium_photo_side);
int listHeightSize = res.getDimensionPixelSize(R.dimen.flickr_list_item_height);
int screenWidth = getScreenWidth();
if (savedInstanceState == null) {
// Weight values determined experimentally by measuring the number of incurred GCs while
// scrolling through the various photo grids/lists.
GlideApp.get(this).preFillBitmapPool(
new PreFillType.Builder(smallGridSize).setWeight(1),
new PreFillType.Builder(mediumGridSize).setWeight(1),
new PreFillType.Builder(screenWidth / 2, listHeightSize).setWeight(6));
}
}
示例14: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_detail);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
getSupportLoaderManager().initLoader(0, null, this);
//Postpone transition here
ActivityCompat.postponeEnterTransition(this);
mPager = (ViewPager) findViewById(R.id.pager);
mPager.setPageTransformer(false, new ParallaxPagerTransformer(R.id.image));
mPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.setPageMargin((int) TypedValue
.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
mPager.setPageMarginDrawable(new ColorDrawable(0x22000000));
mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageScrollStateChanged(int state) {
super.onPageScrollStateChanged(state);
}
@Override
public void onPageSelected(int position) {
if (mCursor != null) {
mCursor.moveToPosition(position);
}
mSelectedItemId = mCursor.getLong(GalleryLoader.Query.COLUMN_IMAGE_ID);
}
});
if (savedInstanceState == null) {
if (getIntent() != null && getIntent().getData() != null) {
mStartId = GalleryContract.GalleryEntry.getItemId(getIntent().getData());
mSelectedItemId = mStartId;
}
}
}
示例15: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_article_detail);
getSupportLoaderManager().initLoader(0, null, this);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
//Postpone transition here
ActivityCompat.postponeEnterTransition(this);
mPager = (ViewPager) findViewById(R.id.pager);
mPager.setPageTransformer(false, new ParallaxPagerTransformer(R.id.photo));
mPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.setPageMargin((int) TypedValue
.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
mPager.setPageMarginDrawable(new ColorDrawable(0x22000000));
mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageScrollStateChanged(int state) {
super.onPageScrollStateChanged(state);
}
@Override
public void onPageSelected(int position) {
if (mCursor != null) {
mCursor.moveToPosition(position);
}
mSelectedItemId = mCursor.getLong(ArticleLoader.Query.COLUMN_ARTICLE_ID);
}
});
if (savedInstanceState == null) {
if (getIntent() != null && getIntent().getData() != null) {
mStartId = ArticleContract.ArticleEntry.getItemId(getIntent().getData());
mSelectedItemId = mStartId;
}
}
}