帮助你创建视差效果引导页的Android库slidingtutorial
VeraManley
9年前
帮助你创建视差效果引导页的Android库,类似于谷歌官方应用中常见的引导效果。细节到位,自定义强,使用简单,还可无限循环。
使用说明:
首先添加依赖:
dependencies { compile 'com.cleveroad:slidingtutorial:0.9.3' }
在你创建了必须继承PageFragment的每个fragment之后,你还必须用image创建xml文件。
public class FirstCustomPageFragment extends PageFragment { @Override protected int getLayoutResId() { // layout id of fragment return R.layout.fragment_page_first; } @Override protected TransformItem[] provideTransformItems() { // list of transformation items return new TransformItem[]{ new TransformItem(R.id.ivFirstImage, true, 20), new TransformItem(R.id.ivSecondImage, false, 6), new TransformItem(R.id.ivThirdImage, true, 8), new TransformItem(R.id.ivFourthImage, false, 10), new TransformItem(R.id.ivFifthImage, false, 3), new TransformItem(R.id.ivSixthImage, false, 9), new TransformItem(R.id.ivSeventhImage, false, 14), new TransformItem(R.id.ivEighthImage, false, 7) }; } }
然后你需要把这些fragments放在主slidingtutroial fragment中:
public class CustomPresentationPagerFragment extends PresentationPagerFragment { @Override public int getLayoutResId() { // layout id of fragment return R.layout.fragment_presentation; } @Override public int getViewPagerResId() { // id of view pager return R.id.viewPager; } @Override public int getIndicatorResId() { // id of circular indicator return R.id.indicator; } @Override public int getButtonSkipResId() { // id of skip button return R.id.tvSkip; } @Override protected int getPagesCount() { // total number of pages return 3; } @Override protected PageFragment getPage(int position) { // get page for position if (position == 0) return new FirstCustomPageFragment(); if (position == 1) return new SecondCustomPageFragment(); if (position == 2) return new ThirdCustomPageFragment(); throw new IllegalArgumentException("Unknown position: " + position); } @ColorInt @Override protected int getPageColor(int position) { // get color of page if (position == 0) return ContextCompat.getColor(getContext(), android.R.color.holo_orange_dark); if (position == 1) return ContextCompat.getColor(getContext(), android.R.color.holo_green_dark); if (position == 2) return ContextCompat.getColor(getContext(), android.R.color.holo_blue_dark); return Color.TRANSPARENT; } @Override protected boolean isInfiniteScrollEnabled() { // enable/disable infinite scroll behavior return true; } @Override protected boolean onSkipButtonClicked() { // your own behavior goes here // ... // return true to consume click event, false otherwise return true; } }
相关文章: Case Study: Sliding tutorial for Android by Cleveroad 。