├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── sjxz │ │ └── viewpagerdesignanim │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── sjxz │ │ │ └── viewpagerdesignanim │ │ │ ├── AnimTransformer.java │ │ │ ├── CardAdapter.java │ │ │ ├── CardItem.java │ │ │ ├── CardPagerAdapter.java │ │ │ ├── CustomView.java │ │ │ ├── GuidePagerAdapter.java │ │ │ ├── LogUtils.java │ │ │ ├── MainActivity.java │ │ │ ├── SFragment.java │ │ │ └── SplashAnimTransformer.java │ └── res │ │ ├── anim │ │ └── splash.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── adapter.xml │ │ └── fragment_adapter.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── sjxz │ └── viewpagerdesignanim │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img-holder ├── 1.png ├── 2.png ├── 3.png └── 4.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | ViewPagerDesignAnim -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ViewPagerDesignAnim 2 | ## 自定义View动画效果,ViewPager手势操作以及动画效果展示 3 | # 作者 # 4 | --- 5 | 6 | WYH_Healer  7 | 8 | >Csdn:[WYH_Healer的博客](http://blog.csdn.net/wyh_healer) 9 | 10 | --- 11 | 在本篇代码中详细的解读了每一行代码的作用性,以及参考已有的文章代码进行知识梳理,有兴趣的同学可以学习一下,互帮互助,不做重复的轮胎~ 12 |   13 | #### 首页的轮播图片控制动画是通过ViewPager.PageTransformer里实现transformPage方法 14 | ## ![image](https://github.com/wyhnihaook/ViewPagerDesignAnim/raw/master/img-holder/1.png) 15 | #### 友好的欢迎页面体验 16 | ## ![image](https://github.com/wyhnihaook/ViewPagerDesignAnim/raw/master/img-holder/2.png) 17 | #### 自定义View进度条更改实现动画效果(类似加速仪) 18 | ## ![image](https://github.com/wyhnihaook/ViewPagerDesignAnim/raw/master/img-holder/3.png) 19 | #### 通过实现ViewPager.OnPageChangeListener, ViewPager.PageTransformer,具体逻辑代码在onPageScrolled方法中实现,并且设置ViewPager的属性“clipToPadding”和各个Padding实现 20 | ## ![image](https://github.com/wyhnihaook/ViewPagerDesignAnim/raw/master/img-holder/4.png) 21 | 22 | >下载的童鞋希望多多star and fork; 23 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.sjxz.viewpagerdesignanim" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | compile 'com.android.support:design:23.4.0' 27 | compile 'com.android.support:cardview-v7:23.4.0' 28 | } 29 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Android\2.1.1SDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/sjxz/viewpagerdesignanim/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/sjxz/viewpagerdesignanim/AnimTransformer.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | import android.support.v4.view.ViewPager; 4 | import android.support.v7.widget.CardView; 5 | import android.view.View; 6 | 7 | /** 8 | * @author WYH_Healer 9 | * @email 3425934925@qq.com 10 | * Created by xz on 2017/4/6. 11 | * Role:动画效果展示 12 | */ 13 | public class AnimTransformer implements ViewPager.OnPageChangeListener, ViewPager.PageTransformer { 14 | 15 | private ViewPager mViewPager;//设置滑动时候的监听 16 | private CardAdapter mAdapter;//获取相应的Item用于动画展示 17 | private float mLastOffset;//记录最后的位置,用于判断左滑还是右滑 18 | 19 | public boolean checkScale; 20 | 21 | 22 | public AnimTransformer(ViewPager viewPager, CardAdapter adapter) { 23 | mAdapter = adapter; 24 | mViewPager = viewPager; 25 | viewPager.addOnPageChangeListener(this); 26 | 27 | } 28 | 29 | @Override 30 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 31 | //动画展示在滚动的过程中 32 | 33 | //对滚动事件监听之后发现,往右滑动的时候position会立刻变为当前-1的状态,而往左滑需要完全确认(操作手势为up的情况)才会累加+1 34 | //总结出如果往右滚动position需要在原有上+1才是目前的position,而当前显示的position则是下个可能切换的position 35 | //往左滚动的position一直是当前的position直到up手势操作之后进行切换,而position+1是下一个可能切换的position 36 | 37 | //1.需一个记录当前真是position的对象 38 | int realCurrentPosition; 39 | //2.需要对下一个item进行操作,所以也需要获取nextPosition的坐标 40 | int nextPosition; 41 | //3.由于使用了cardView存在阴影部分,需要获取宽度对其进行渐变 42 | float baseElevation = mAdapter.getBaseElevation(); 43 | //4.根据打印的log发现,向左滑动是从1->0,往右滑动是从0->1,移动到某一数据时候即可进行界面切换,可以将其视为滑动动画渐变过程 44 | float realOffset; 45 | //5.判断左滑右滑,用于做item的渐变操作 46 | // 往右滑减小(从1开始---减小到一定比例即(1-左滑切换的比例0.6=0.4)) 47 | // 往左滑增加(从0开始增加---增加到一定比例切换item例如0.6) 48 | boolean goingLeft = mLastOffset > positionOffset;//判断是左滑右滑 49 | 50 | //由于滑动事件的规律,已经左滑右滑界面的不同性进行界面操作 51 | if (goingLeft) { 52 | //右滑,显示左边模块 53 | realCurrentPosition = position + 1; 54 | nextPosition = position; 55 | realOffset = 1 - positionOffset;//这里保持数据一致,默认都是从1->0数据进行改变 56 | } else { 57 | //左滑,显示右边模块 58 | nextPosition = position + 1; 59 | 60 | realCurrentPosition = position; 61 | realOffset = positionOffset;//这里保持数据一致,默认都是从1->0数据进行改变 62 | } 63 | 64 | //判断下一个显示的position是否是最后一个item的index 65 | if (nextPosition > mAdapter.getCount() - 1 66 | || realCurrentPosition > mAdapter.getCount() - 1) { 67 | return; 68 | } 69 | 70 | //获取当前显示相应的item 71 | CardView cardView = mAdapter.getCardViewAt(realCurrentPosition); 72 | 73 | if (cardView != null) { 74 | 75 | if (checkScale) { 76 | cardView.setScaleX((float) (1 + 0.1 * (1 - realOffset)));//渐变过程是1.1->1 77 | cardView.setScaleY((float) (1 + 0.1 * (1 - realOffset)));//渐变过程是1.1->1 78 | } 79 | 80 | 81 | //字体渐变, 82 | mAdapter.getViewAlpha(cardView).setAlpha((1 - realOffset)); 83 | 84 | //设置阴影处的渐变,将阴影区间从最大值渐变成最小值,即阴影宽度 85 | cardView.setCardElevation(baseElevation + baseElevation * (mAdapter.MAX_ELEVATION_FACTOR) * (1 - realOffset)); 86 | } 87 | 88 | CardView cardViewNext = mAdapter.getCardViewAt(nextPosition); 89 | 90 | if (cardViewNext != null) { 91 | if (checkScale) { 92 | cardViewNext.setScaleX((float) (1 + 0.1 * (realOffset))); 93 | cardViewNext.setScaleY((float) (1 + 0.1 * (realOffset))); 94 | } 95 | 96 | 97 | //字体逐渐渐变显示 98 | mAdapter.getViewAlpha(cardViewNext).setAlpha((realOffset)); 99 | 100 | //将要显示的数据逐渐变大 101 | cardViewNext.setCardElevation((baseElevation + baseElevation 102 | * (CardAdapter.MAX_ELEVATION_FACTOR) * (realOffset))); 103 | } 104 | 105 | mLastOffset = positionOffset; 106 | 107 | } 108 | 109 | @Override 110 | public void onPageSelected(int position) { 111 | 112 | } 113 | 114 | @Override 115 | public void onPageScrollStateChanged(int state) { 116 | 117 | } 118 | 119 | @Override 120 | public void transformPage(View page, float position) { 121 | 122 | } 123 | 124 | //组合动画点击选中效果 125 | public void initAnim(boolean checkScale, int index) { 126 | 127 | CardView currentCard = mAdapter.getCardViewAt(mViewPager.getCurrentItem()); 128 | if (currentCard == null) { 129 | return; 130 | } 131 | if (index == 0) { 132 | currentCard.animate().scaleY(checkScale ? 1.1f : 1); 133 | currentCard.animate().scaleX(checkScale ? 1.1f : 1); 134 | 135 | this.checkScale = checkScale; 136 | } 137 | 138 | } 139 | 140 | 141 | } 142 | -------------------------------------------------------------------------------- /app/src/main/java/com/sjxz/viewpagerdesignanim/CardAdapter.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | import android.support.v7.widget.CardView; 4 | import android.view.View; 5 | 6 | /** 7 | * @author WYH_Healer 8 | * @email 3425934925@qq.com 9 | * Created by xz on 2017/4/6. 10 | * Role: 11 | */ 12 | public interface CardAdapter { 13 | 14 | int MAX_ELEVATION_FACTOR = 8; 15 | 16 | float getBaseElevation();// 17 | 18 | CardView getCardViewAt(int position); 19 | 20 | int getCount(); 21 | 22 | View getViewAlpha( View view); 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/sjxz/viewpagerdesignanim/CardItem.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | /** 4 | * @author WYH_Healer 5 | * @email 3425934925@qq.com 6 | * Created by xz on 2017/4/6. 7 | * Role: 8 | */ 9 | public class CardItem { 10 | 11 | 12 | private int mTextResource; 13 | private int mTitleResource; 14 | 15 | public CardItem(int title, int text) { 16 | mTitleResource = title; 17 | mTextResource = text; 18 | } 19 | 20 | public int getText() { 21 | return mTextResource; 22 | } 23 | 24 | public int getTitle() { 25 | return mTitleResource; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/sjxz/viewpagerdesignanim/CardPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | import android.support.v4.view.PagerAdapter; 4 | import android.support.v7.widget.CardView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * @author WYH_Healer 15 | * @email 3425934925@qq.com 16 | * Created by xz on 2017/4/6. 17 | * Role:直接添加布局相关 18 | */ 19 | public class CardPagerAdapter extends PagerAdapter implements CardAdapter{ 20 | 21 | 22 | private List mViews; 23 | private List mData; 24 | private float mBaseElevation; 25 | 26 | public CardPagerAdapter() { 27 | mData = new ArrayList<>(); 28 | mViews = new ArrayList<>(); 29 | } 30 | 31 | public void addCardItem(CardItem item) { 32 | mViews.add(null); 33 | mData.add(item); 34 | } 35 | 36 | @Override 37 | public float getBaseElevation() { 38 | return mBaseElevation; 39 | } 40 | 41 | @Override 42 | public CardView getCardViewAt(int position) { 43 | return mViews.get(position); 44 | } 45 | 46 | @Override 47 | public View getViewAlpha( View view) { 48 | return view.findViewById(R.id.titleTextView); 49 | } 50 | 51 | 52 | 53 | 54 | 55 | 56 | @Override 57 | public int getCount() { 58 | return mData.size(); 59 | } 60 | 61 | @Override 62 | public boolean isViewFromObject(View view, Object object) { 63 | return view == object; 64 | } 65 | 66 | @Override 67 | public Object instantiateItem(ViewGroup container, int position) { 68 | View view = LayoutInflater.from(container.getContext()) 69 | .inflate(R.layout.adapter, container, false); 70 | container.addView(view); 71 | bind(mData.get(position), view); 72 | CardView cardView = (CardView) view.findViewById(R.id.cardView); 73 | 74 | if (mBaseElevation == 0) { 75 | mBaseElevation = cardView.getCardElevation(); 76 | } 77 | 78 | cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);//设置最大高度 79 | mViews.set(position, cardView); 80 | return view; 81 | } 82 | 83 | @Override 84 | public void destroyItem(ViewGroup container, int position, Object object) { 85 | container.removeView((View) object); 86 | mViews.set(position, null); 87 | } 88 | 89 | private void bind(CardItem item, View view) { 90 | TextView titleTextView = (TextView) view.findViewById(R.id.titleTextView); 91 | TextView contentTextView = (TextView) view.findViewById(R.id.contentTextView); 92 | titleTextView.setText(item.getTitle()); 93 | contentTextView.setText(item.getText()); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/java/com/sjxz/viewpagerdesignanim/CustomView.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.content.Context; 5 | import android.graphics.Canvas; 6 | import android.graphics.DashPathEffect; 7 | import android.graphics.Paint; 8 | import android.graphics.RectF; 9 | import android.text.TextPaint; 10 | import android.text.TextUtils; 11 | import android.util.AttributeSet; 12 | import android.view.View; 13 | 14 | /** 15 | * @author WYH_Healer 16 | * @email 3425934925@qq.com 17 | * Created by xz on 2017/4/1. 18 | * Role:实现要求。圆弧显示进度,中间固定显示三行文字 19 | */ 20 | public class CustomView extends View { 21 | 22 | private float density; 23 | 24 | 25 | //当前的进度 26 | private float progress = 0; 27 | 28 | private String first = "Healer自定义"; 29 | private String sceond = "进度条"; 30 | private String third = "80%"; 31 | 32 | //字体大小 33 | private float textSize; 34 | 35 | //圆弧半径 36 | private float radius; 37 | private float radiusInside; 38 | 39 | //绘制图片的大小 40 | private RectF rectF; 41 | private RectF rectFInside; 42 | private RectF rectFprogress; 43 | 44 | //绘制文字的画笔 45 | private TextPaint textPaint; 46 | 47 | 48 | //固定的宽高 49 | private float width; 50 | private float height; 51 | 52 | private DashPathEffect dashPathEffect;//圆弧虚线效果 53 | 54 | private ValueAnimator outerProgressAnim; 55 | private long duration = 1000; 56 | private long progressDelay = 350; 57 | private float outerProgressValue = 0; 58 | public CustomView(Context context) { 59 | super(context, null); 60 | } 61 | 62 | public CustomView(Context context, AttributeSet attrs) { 63 | super(context, attrs, 0); 64 | //默认情况下会执行两个参数的构造方法 65 | textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);//消除绘制时候的锯齿 66 | textPaint.setTextAlign(Paint.Align.CENTER);//设置绘制的文字水平居中 67 | 68 | rectF = new RectF();//外空心圆弧大小 69 | rectFInside = new RectF();//内空心虚线圆弧大小 70 | rectFprogress=new RectF();//进度条 71 | 72 | density = context.getResources().getDisplayMetrics().density;//获取屏幕密度 73 | dashPathEffect = new DashPathEffect(new float[]{density * 3, density * 3}, 1); 74 | //避免density获取失败导致绘制失败的异常 75 | 76 | initAnim(); 77 | if (isInEditMode()) { 78 | return; 79 | } 80 | } 81 | 82 | public CustomView(Context context, AttributeSet attrs, int defStyleAttr) { 83 | super(context, attrs, defStyleAttr); 84 | } 85 | 86 | @Override 87 | protected void onDraw(Canvas canvas) { 88 | super.onDraw(canvas); 89 | textPaint.setStrokeWidth(0.0f); 90 | //获取固定的宽高 91 | //在onmeasure不进行复写的情况下,View的高度设定就返回确切高度或者是没有固定宽高的父容器的wrap_content或者是match_parent返回整屏 92 | width = getWidth(); 93 | height = getHeight(); 94 | 95 | textSize = height / 15;//设计字体大小 96 | radius = height / 9 * 4f;//半径上下相加不能超过height 97 | radiusInside = radius * 7 / 8f;//内圆的半径 98 | 99 | //设置字体画笔 100 | textPaint.setStyle(Paint.Style.STROKE);//空心 101 | textPaint.setTextSize(textSize); 102 | textPaint.setColor(getContext().getResources().getColor(R.color.gplus_color_3)); 103 | 104 | //为绘制圆弧做准备工作,在指定范围内切出圆弧存在的范围(PS:圆弧就是一个圆不画完) 105 | 106 | progress = Float.valueOf(progress) / 100;//占总数的百分比 107 | progress = Math.min(progress, 1f);//最高就是100%,避免传递数据错误产生误差值,降低用户体验 108 | 109 | //根据当前公司给的切面自己计算切面 110 | final float startAngle = -210f; 111 | final float sweepAngle = 240f; 112 | 113 | 114 | 115 | //开始绘制圆弧 116 | //1.首先将canvas画布平移到最中心,便于观察,为了规范书写(避免该次操作画布影响后续操作,需要save以及最后的restore) 117 | //2.确认圆弧范围,画笔样式(每次样式变化的情况都要设计画笔设置重置等) 118 | //3.绘制相应文本内容 119 | //4.绘制虚线 120 | //5.绘制进度 121 | 122 | canvas.save(); 123 | canvas.translate(width / 2f, height / 2f); 124 | 125 | rectF.set(-radius, -radius, radius, radius);//这里要注意平移之后上方依然保持和之前一样是负的坐标,这里要熟悉坐标系,和普通的Y轴是相反的 126 | rectFInside.set(-radiusInside, -radiusInside, radiusInside, radiusInside); 127 | rectFprogress.set(-(radius-(radius-radiusInside)/2), 128 | -(radius-(radius-radiusInside)/2),(radius-(radius-radiusInside)/2),(radius-(radius-radiusInside)/2)); 129 | 130 | canvas.drawArc(rectF, startAngle, sweepAngle, false, textPaint); 131 | 132 | textPaint.setStyle(Paint.Style.FILL); 133 | textPaint.setColor(getContext().getResources().getColor(R.color.gplus_color_2)); 134 | textPaint.setTextSize(textSize); 135 | 136 | canvas.drawText(first, 0, -textSize*2, textPaint); 137 | textPaint.setTextSize(textSize * 1.1f); 138 | textPaint.setColor(getContext().getResources().getColor(R.color.gplus_color_3)); 139 | canvas.drawText(sceond, 0, 0, textPaint); 140 | textPaint.setTextSize(textSize * 1.3f); 141 | textPaint.setColor(getContext().getResources().getColor(R.color.gplus_color_4)); 142 | canvas.drawText(Math.round(progress*100)+"%", 0, textSize * 2, textPaint); 143 | 144 | 145 | //设置绘制虚线 146 | textPaint.setStyle(Paint.Style.STROKE); 147 | textPaint.setColor(getContext().getResources().getColor(R.color.gplus_color_3)); 148 | textPaint.setPathEffect(dashPathEffect); 149 | canvas.drawArc(rectFInside, startAngle, sweepAngle, false, textPaint); 150 | 151 | //绘制进度,范围依然是最外层的范围,绘制画笔的宽度就是外层-内层的宽度 152 | textPaint.setStrokeWidth(radius-radiusInside); 153 | textPaint.setPathEffect(null); 154 | textPaint.setColor(getContext().getResources().getColor(R.color.gplus_color_3)); 155 | canvas.drawArc(rectFprogress, startAngle, sweepAngle * progress, false, textPaint); 156 | 157 | 158 | canvas.restore(); 159 | } 160 | 161 | 162 | //设置百分比进度,默认情况下,最高为100% 163 | public void setDataProgress(float progress, String first, String second, String third) { 164 | if (progress >= 0) { 165 | this.progress = progress; 166 | updateAnimValue(progress); 167 | invalidate();//重绘界面 168 | } 169 | if (first != null && !TextUtils.isEmpty(first)) { 170 | this.first = first; 171 | } 172 | 173 | if (second != null && !TextUtils.isEmpty(second)) { 174 | this.sceond = second; 175 | } 176 | 177 | if (third != null && !TextUtils.isEmpty(third)) { 178 | this.third = third; 179 | } 180 | } 181 | 182 | //更改进度 183 | public void changeProgress(float progress){ 184 | if (progress >= 0) { 185 | this.progress = progress; 186 | updateAnimValue(progress); 187 | invalidate();//重绘界面 188 | } 189 | } 190 | 191 | //添加展示动画效果 192 | /** 193 | * 初始化属性动画 194 | */ 195 | private void initAnim() { 196 | outerProgressAnim = new ValueAnimator(); 197 | outerProgressAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 198 | @Override 199 | public void onAnimationUpdate(ValueAnimator animation) { 200 | Float value = (Float) animation.getAnimatedValue(); 201 | updateOuterProgressValue(value); 202 | outerProgressValue=value; 203 | } 204 | }); 205 | } 206 | 207 | private void updateOuterProgressValue(float value) { 208 | setOuterAnimAngle(value); 209 | } 210 | 211 | public void setOuterAnimAngle(float value){ 212 | this.progress=value; 213 | invalidate(); 214 | } 215 | 216 | 217 | private void updateAnimValue(float progress) { 218 | outerProgressAnim.setFloatValues(outerProgressValue, progress);//设置进度范围 219 | outerProgressAnim.setDuration(duration + progressDelay);//设置延时时间 220 | outerProgressAnim.start(); 221 | 222 | } 223 | 224 | } 225 | -------------------------------------------------------------------------------- /app/src/main/java/com/sjxz/viewpagerdesignanim/GuidePagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | import android.support.v4.app.FragmentManager; 4 | import android.support.v4.app.FragmentPagerAdapter; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author WYH_Healer 10 | * @email 3425934925@qq.com 11 | * Created by xz on 2017/4/7. 12 | * Role: 13 | */ 14 | public class GuidePagerAdapter extends FragmentPagerAdapter { 15 | 16 | 17 | List datas ; 18 | 19 | 20 | public GuidePagerAdapter(FragmentManager fm,List datas) { 21 | super(fm); 22 | this.datas=datas; 23 | } 24 | 25 | 26 | @Override 27 | public int getCount() { 28 | return datas.size(); 29 | } 30 | 31 | 32 | @Override 33 | public SFragment getItem(int position) { 34 | return datas.get(position); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/sjxz/viewpagerdesignanim/LogUtils.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | import android.text.TextUtils; 4 | import android.util.Log; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * --------------------------------------------------- 10 | * 版 权 : 杭州石谷网络科技有限公司 版权所有 (c) 2015 11 | * 作 者 : Star 12 | * 版 本 : 1.0 13 | * 创建日期 : 2015/10/20 15:51 14 | * 描 述 : 15 | * 1.日志输出控制类 (Description) 16 | * --------------------------------------------------- 17 | */ 18 | public class LogUtils { 19 | /** 20 | * 日志输出级别NONE 21 | */ 22 | public static final int LEVEL_NONE = 0; 23 | /** 24 | * 日志输出级别V 25 | */ 26 | public static final int LEVEL_VERBOSE = 1; 27 | /** 28 | * 日志输出级别D 29 | */ 30 | public static final int LEVEL_DEBUG = 2; 31 | /** 32 | * 日志输出级别I 33 | */ 34 | public static final int LEVEL_INFO = 3; 35 | /** 36 | * 日志输出级别W 37 | */ 38 | public static final int LEVEL_WARN = 4; 39 | /** 40 | * 日志输出级别E 41 | */ 42 | public static final int LEVEL_ERROR = 5; 43 | /** 44 | * 日志输出级别 输出所有 45 | */ 46 | public static final int LEVEL_ALL = 6; 47 | 48 | /** 49 | * 日志输出时的TAG 50 | */ 51 | private static String mTag = "wyh"; 52 | /** 53 | * 是否允许输出log 54 | */ 55 | private static int mDebuggable = LEVEL_ALL; 56 | 57 | /** 58 | * 用于记时的变量 59 | */ 60 | private static long mTimestamp = 0; 61 | /** 62 | * 写文件的锁对象 63 | */ 64 | private static final Object mLogLock = new Object(); 65 | 66 | /** 67 | * 以级别为 d 的形式输出LOG 68 | */ 69 | public static void v(String msg) { 70 | if (mDebuggable >= LEVEL_VERBOSE) { 71 | Log.v(mTag, msg); 72 | } 73 | } 74 | 75 | /** 76 | * 以级别为 d 的形式输出LOG 77 | */ 78 | public static void d(String msg) { 79 | if (mDebuggable >= LEVEL_DEBUG) { 80 | Log.d(mTag, msg); 81 | } 82 | } 83 | 84 | /** 85 | * 以级别为 i 的形式输出LOG 86 | */ 87 | public static void i(String msg) { 88 | if (mDebuggable >= LEVEL_INFO) { 89 | Log.i(mTag, msg); 90 | } 91 | } 92 | 93 | 94 | /** 95 | * 以级别为 i 的形式输出LOG 96 | */ 97 | public static void i(String tag,String msg) { 98 | if (mDebuggable >= LEVEL_INFO) { 99 | Log.i(tag, msg); 100 | } 101 | } 102 | 103 | /** 104 | * 以级别为 w 的形式输出LOG 105 | */ 106 | public static void w(String msg) { 107 | if (mDebuggable >= LEVEL_WARN) { 108 | Log.w(mTag, msg); 109 | } 110 | } 111 | 112 | /** 113 | * 以级别为 w 的形式输出Throwable 114 | */ 115 | public static void w(Throwable tr) { 116 | if (mDebuggable >= LEVEL_WARN) { 117 | Log.w(mTag, "", tr); 118 | } 119 | } 120 | 121 | /** 122 | * 以级别为 w 的形式输出LOG信息和Throwable 123 | */ 124 | public static void w(String msg, Throwable tr) { 125 | if (mDebuggable >= LEVEL_WARN && null != msg) { 126 | Log.w(mTag, msg, tr); 127 | } 128 | } 129 | 130 | /** 131 | * 以级别为 e 的形式输出LOG 132 | */ 133 | public static void e(String msg) { 134 | if (mDebuggable >= LEVEL_ERROR) { 135 | Log.e(mTag, msg); 136 | } 137 | } 138 | 139 | /** 140 | * 以级别为 e 的形式输出Throwable 141 | */ 142 | public static void e(Throwable tr) { 143 | if (mDebuggable >= LEVEL_ERROR) { 144 | Log.e(mTag, "", tr); 145 | } 146 | } 147 | 148 | /** 149 | * 以级别为 e 的形式输出LOG信息和Throwable 150 | */ 151 | public static void e(String msg, Throwable tr) { 152 | if (mDebuggable >= LEVEL_ERROR && null != msg) { 153 | Log.e(mTag, msg, tr); 154 | } 155 | } 156 | 157 | /** 158 | * 把Log存储到文件中 159 | * 160 | * @param log 需要存储的日志 161 | * @param path 存储路径 162 | */ 163 | // public static void log2File(String log, String path) { 164 | // log2File(log, path, true); 165 | // } 166 | // 167 | // public static void log2File(String log, String path, boolean append) { 168 | // synchronized (mLogLock) { 169 | // FileUtils.writeFile(log + "\r\n", path, append); 170 | // } 171 | // } 172 | 173 | /** 174 | * 以级别为 e 的形式输出msg信息,附带时间戳,用于输出一个时间段起始点 175 | * 176 | * @param msg 需要输出的msg 177 | */ 178 | public static void msgStartTime(String msg) { 179 | mTimestamp = System.currentTimeMillis(); 180 | if (!TextUtils.isEmpty(msg)) { 181 | e("[Started:" + mTimestamp + "]" + msg); 182 | } 183 | } 184 | 185 | /** 186 | * 以级别为 e 的形式输出msg信息,附带时间戳,用于输出一个时间段结束点* @param msg 需要输出的msg 187 | */ 188 | public static void elapsed(String msg) { 189 | long currentTime = System.currentTimeMillis(); 190 | long elapsedTime = currentTime - mTimestamp; 191 | mTimestamp = currentTime; 192 | e("[Elapsed:" + elapsedTime + "]" + msg); 193 | } 194 | 195 | public static void printList(List list) { 196 | if (list == null || list.size() < 1) { 197 | return; 198 | } 199 | int size = list.size(); 200 | i("---begin---"); 201 | for (int i = 0; i < size; i++) { 202 | i(i + ":" + list.get(i).toString()); 203 | } 204 | i("---end---"); 205 | } 206 | 207 | public static void printArray(T[] array) { 208 | if (array == null || array.length < 1) { 209 | return; 210 | } 211 | int length = array.length; 212 | i("---begin---"); 213 | for (int i = 0; i < length; i++) { 214 | i(i + ":" + array[i].toString()); 215 | } 216 | i("---end---"); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /app/src/main/java/com/sjxz/viewpagerdesignanim/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.util.DisplayMetrics; 7 | import android.view.GestureDetector; 8 | import android.view.MotionEvent; 9 | import android.view.View; 10 | import android.view.animation.Animation; 11 | import android.view.animation.AnimationUtils; 12 | import android.widget.CheckBox; 13 | import android.widget.CompoundButton; 14 | import android.widget.SeekBar; 15 | import android.widget.TextView; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener, SeekBar.OnSeekBarChangeListener, View.OnTouchListener { 21 | 22 | private CustomView customView; 23 | 24 | 25 | private ViewPager mViewPager; 26 | 27 | private AnimTransformer animTransformer;//viewpager展示动画效果 28 | private CardPagerAdapter mCardAdapter; 29 | 30 | private CheckBox checkScale; 31 | 32 | private SeekBar seekbar; 33 | private TextView text_progress; 34 | 35 | private int progress=50;//显示初始化定义的进度 36 | 37 | 38 | /** 39 | * 欢迎界面相关数据 40 | * */ 41 | 42 | private ViewPager viewPager; 43 | 44 | private GuidePagerAdapter guidePagerAdapter; 45 | 46 | private List datas; 47 | 48 | private GestureDetector gestureDetector; 49 | 50 | private int mFlaggingWidth; 51 | 52 | Animation animation; 53 | 54 | boolean scrollEnable=true; 55 | 56 | @Override 57 | protected void onCreate(Bundle savedInstanceState) { 58 | super.onCreate(savedInstanceState); 59 | setContentView(R.layout.activity_main); 60 | 61 | mViewPager = (ViewPager) findViewById(R.id.viewPager); 62 | 63 | checkScale=(CheckBox)findViewById(R.id.checkScale); 64 | checkScale.setOnCheckedChangeListener(this); 65 | 66 | seekbar=(SeekBar)findViewById(R.id.seekbar); 67 | text_progress=(TextView)findViewById(R.id.text_progress); 68 | seekbar.setOnSeekBarChangeListener(this); 69 | 70 | customView= (CustomView) findViewById(R.id.customView); 71 | 72 | customView.setDataProgress(progress*1.0f,"自定义控件哦","欧巴进度","50%"); 73 | 74 | seekbar.setProgress(progress);//初始化当前数据 75 | 76 | 77 | //Viewpager的setAdapter内的对象item有两种实现方式,相对简单的对象item,一个布局就能实现,不需要任何实时加载的数据;需要fragment进行搭档 78 | mCardAdapter = new CardPagerAdapter(); 79 | mCardAdapter.addCardItem(new CardItem(R.string.title, R.string.text)); 80 | mCardAdapter.addCardItem(new CardItem(R.string.title, R.string.text)); 81 | mCardAdapter.addCardItem(new CardItem(R.string.title, R.string.text)); 82 | mCardAdapter.addCardItem(new CardItem(R.string.title, R.string.text)); 83 | 84 | animTransformer = new AnimTransformer(mViewPager, mCardAdapter); 85 | 86 | mViewPager.setAdapter(mCardAdapter); 87 | mViewPager.setPageTransformer(false, animTransformer); 88 | mViewPager.setOffscreenPageLimit(3); 89 | 90 | 91 | initSplash(); 92 | 93 | } 94 | 95 | /** 96 | * 使欢迎界面更加友好 97 | * */ 98 | private void initSplash() { 99 | viewPager=(ViewPager)findViewById(R.id.viewPager_splash); 100 | 101 | animation= AnimationUtils.loadAnimation(this,R.anim.splash); 102 | animation.setAnimationListener(new Animation.AnimationListener() { 103 | @Override 104 | public void onAnimationStart(Animation animation) { 105 | scrollEnable=false; 106 | } 107 | 108 | @Override 109 | public void onAnimationEnd(Animation animation) { 110 | viewPager.setVisibility(View.GONE); 111 | } 112 | 113 | @Override 114 | public void onAnimationRepeat(Animation animation) { 115 | 116 | } 117 | }); 118 | 119 | DisplayMetrics dm = new DisplayMetrics(); 120 | getWindowManager().getDefaultDisplay().getMetrics(dm); 121 | mFlaggingWidth = dm.widthPixels / 5; 122 | 123 | 124 | datas=new ArrayList<>(); 125 | datas.add(new SFragment()); 126 | datas.add(new SFragment()); 127 | datas.add(new SFragment()); 128 | datas.add(new SFragment()); 129 | datas.add(new SFragment()); 130 | datas.add(new SFragment()); 131 | 132 | guidePagerAdapter=new GuidePagerAdapter(getSupportFragmentManager(),datas); 133 | 134 | gestureDetector=new GestureDetector(new WelcomePagerTouchListener()); 135 | 136 | 137 | viewPager.setOnTouchListener(this); 138 | viewPager.setAdapter(guidePagerAdapter); 139 | mViewPager.setOffscreenPageLimit(6); 140 | viewPager.setPageTransformer(false,new SplashAnimTransformer()); 141 | 142 | } 143 | 144 | @Override 145 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 146 | switch (buttonView.getId()){ 147 | case R.id.checkScale: 148 | animTransformer.initAnim(isChecked,0); 149 | break; 150 | } 151 | } 152 | 153 | @Override 154 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 155 | //滚动数据监听 156 | customView.changeProgress(progress*1.0f); 157 | text_progress.setText("当前进度:"+progress+"%"); 158 | } 159 | 160 | @Override 161 | public void onStartTrackingTouch(SeekBar seekBar) { 162 | //开始移动 163 | } 164 | 165 | @Override 166 | public void onStopTrackingTouch(SeekBar seekBar) { 167 | //停止移动 168 | } 169 | 170 | 171 | @Override 172 | public boolean onTouch(View v, MotionEvent event) { 173 | return scrollEnable?this.gestureDetector.onTouchEvent(event):false; 174 | } 175 | 176 | /** 177 | * 页面手势滑动监听:监听最后一页的横向滑动,进入应用 178 | */ 179 | private class WelcomePagerTouchListener extends GestureDetector.SimpleOnGestureListener { 180 | @Override 181 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 182 | if(viewPager.getCurrentItem() == (guidePagerAdapter.getCount() - 1)) { 183 | if(Math.abs(e1.getX() - e2.getX()) > Math.abs(e1.getY() - e2.getY()) && (e1.getX() - e2.getX() <= (-mFlaggingWidth) || e1.getX() - e2.getX() >= mFlaggingWidth)) { 184 | if(e1.getX() - e2.getX() >= mFlaggingWidth) { 185 | //渐变消失 186 | viewPager.startAnimation(animation); 187 | return true; 188 | } 189 | } 190 | } 191 | return false; 192 | } 193 | } 194 | 195 | //为了防止在动画过程中进行界面滑动效果 196 | @Override 197 | public boolean onTouchEvent(MotionEvent event) { 198 | return scrollEnable?super.onTouchEvent(event):false; 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /app/src/main/java/com/sjxz/viewpagerdesignanim/SFragment.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v7.widget.CardView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | /** 12 | * @author WYH_Healer 13 | * @email 3425934925@qq.com 14 | * Created by xz on 2017/4/7. 15 | * Role: 16 | */ 17 | public class SFragment extends Fragment { 18 | 19 | private CardView mCardView; 20 | 21 | 22 | public static SFragment sFragment; 23 | 24 | //比较特殊的类。每次getInstance都需要新建 25 | public synchronized static SFragment getInstance(Bundle bundle) { 26 | 27 | sFragment = new SFragment(); 28 | sFragment.setArguments(bundle); 29 | return sFragment; 30 | } 31 | 32 | @Nullable 33 | @Override 34 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 35 | @Nullable Bundle savedInstanceState) { 36 | View view = inflater.inflate(R.layout.fragment_adapter, container, false); 37 | mCardView = (CardView) view.findViewById(R.id.cardView); 38 | mCardView.setMaxCardElevation(mCardView.getCardElevation() 39 | * CardAdapter.MAX_ELEVATION_FACTOR); 40 | return view; 41 | } 42 | public CardView getCardView() { 43 | return mCardView; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/sjxz/viewpagerdesignanim/SplashAnimTransformer.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | import android.support.v4.view.ViewPager; 4 | import android.view.View; 5 | 6 | /** 7 | * @author WYH_Healer 8 | * @email 3425934925@qq.com 9 | * Created by xz on 2017/4/7. 10 | * Role: 11 | */ 12 | public class SplashAnimTransformer implements ViewPager.PageTransformer { 13 | private static final float MIN_SCALE = 0.75f; 14 | /** 15 | * 举个例子 16 | 17 | a 是第一页 18 | b 是第二页 19 | 当前页为 a, 当 a 向左滑动, 直到滑到 b 时: 20 | a 的position变化是 [-1 , 0] 由 0 慢慢变到 -1 21 | b 的position变化是 ( 0 , 1] 由 1 慢慢变到 0 22 | 23 | 当前页为b, 当 b 向右滑动, 直到滑到a 时: 24 | a 的position变化是 [-1 , 0] 由 -1 慢慢变到 0 25 | b 的position变化是 ( 0 , 1] 由 0 慢慢变到 1 26 | * */ 27 | @Override 28 | public void transformPage(View view, float position) { 29 | int pageWidth = view.getWidth(); 30 | if (position < -1) { // [-Infinity,-1) 31 | // This page is way off-screen to the left. 32 | view.setAlpha(0); 33 | 34 | } else if (position <= 0) { // [-1,0] 35 | // Use the default slide transition when moving to the left page 36 | view.setAlpha(1); 37 | view.setTranslationX(0); 38 | view.setScaleX(1); 39 | view.setScaleY(1); 40 | 41 | } else if (position <= 1) { // (0,1] 42 | // Fade the page out. 43 | view.setAlpha(1 - position); 44 | 45 | // Counteract the default slide transition 这个是和滑动事件不相关的,就是保证第二个view在当前页面展示 46 | view.setTranslationX(pageWidth * -position); 47 | 48 | // Scale the page down (between MIN_SCALE and 1) 49 | float scaleFactor = MIN_SCALE 50 | + (1 - MIN_SCALE) * (1 - Math.abs(position)); 51 | view.setScaleX(scaleFactor); 52 | view.setScaleY(scaleFactor); 53 | 54 | } else { // (1,+Infinity] 55 | // This page is way off-screen to the right. 56 | view.setAlpha(0); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/res/anim/splash.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 15 | 16 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 18 | 19 | 20 | 22 | 23 | 29 | 30 | 34 | 41 | 46 | 47 | 48 | 49 | 50 | 61 | 62 | 63 | 64 | 65 | 66 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /app/src/main/res/layout/adapter.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 15 | 21 | 22 | 27 | 28 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_adapter.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 12 | 13 | 14 | 20 | 21 | 26 | 27 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyhnihaook/ViewPagerDesignAnim/ed44c3d48fe4c45a653c426f8fed9edef6a97628/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyhnihaook/ViewPagerDesignAnim/ed44c3d48fe4c45a653c426f8fed9edef6a97628/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyhnihaook/ViewPagerDesignAnim/ed44c3d48fe4c45a653c426f8fed9edef6a97628/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyhnihaook/ViewPagerDesignAnim/ed44c3d48fe4c45a653c426f8fed9edef6a97628/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyhnihaook/ViewPagerDesignAnim/ed44c3d48fe4c45a653c426f8fed9edef6a97628/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #48A5D1 7 | #3e802f 8 | #f4b400 9 | #427fed 10 | #b23424 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 60dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ViewPagerDesignAnim 3 | 标题渐变 4 | 5 | Healer学习ViewPager自定义动画效果;如果你也喜欢,欢迎您star一下fork一下哦~~ 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/sjxz/viewpagerdesignanim/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.sjxz.viewpagerdesignanim; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.2' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyhnihaook/ViewPagerDesignAnim/ed44c3d48fe4c45a653c426f8fed9edef6a97628/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /img-holder/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyhnihaook/ViewPagerDesignAnim/ed44c3d48fe4c45a653c426f8fed9edef6a97628/img-holder/1.png -------------------------------------------------------------------------------- /img-holder/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyhnihaook/ViewPagerDesignAnim/ed44c3d48fe4c45a653c426f8fed9edef6a97628/img-holder/2.png -------------------------------------------------------------------------------- /img-holder/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyhnihaook/ViewPagerDesignAnim/ed44c3d48fe4c45a653c426f8fed9edef6a97628/img-holder/3.png -------------------------------------------------------------------------------- /img-holder/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyhnihaook/ViewPagerDesignAnim/ed44c3d48fe4c45a653c426f8fed9edef6a97628/img-holder/4.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------