Skip to content

Commit

Permalink
增加viewpager切换动画和设置方法
Browse files Browse the repository at this point in the history
  • Loading branch information
youth5201314 committed Aug 24, 2016
1 parent ddd36d6 commit 86b4d2c
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 23 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ compile project(':banner')
|BannerConfig.LEFT| 指示器居左
|BannerConfig.CENTER| 指示器居中
|BannerConfig.RIGHT| 指示器居右
|BannerConfig.ZOOMOUT| 放大动画
|BannerConfig.DEPTH| 层叠动画
|BannerConfig.ROTATEDOWN| 旋转动画

##方法
|方法名|描述
|---|---|
Expand All @@ -52,7 +56,12 @@ compile project(':banner')
|setImages(Object[]/List<?> imagesUrl,OnLoadImageListener listener)| 设置轮播图片,并且自定义图片加载方式
|setOnBannerClickListener(this)|设置点击事件,下标是从1开始
|setOnBannerImageListener(this)|设置图片加载事件,可以自定义图片加载方式
|setOnPageChangeListener(this)|viewpager的滑动监听
|setOnPageChangeListener(this)|设置viewpager的滑动监听
|setBannerAnimation(int type)|设置viewpager的默认动画
|setPageTransformer(boolean reverseDrawingOrder, ViewPager.PageTransformer transformer)|设置viewpager的自定义动画

### <a href="http://www.springblog.top/2016/08/24/ViewPager%E5%88%87%E6%8D%A2%E5%8A%A8%E7%94%BBPageTransformer%E4%BD%BF%E7%94%A8/" target="_blank"> [ 点击查看 ViewPager的PageTransformer用法 ]


##使用步骤 \* 更多用法请下载demo

Expand Down Expand Up @@ -106,9 +115,13 @@ protected void onCreate(Bundle savedInstanceState) {

## 更新说明

#### v1.2.7
增加viewpager的切换默认几种动画,和自定义动画方法

#### v1.2.5
修改bug
* app:title_height="标题栏高度",高度过小文字不显示问题

#### v1.2.4
优化更新
* app:title_background="标题栏的背景色"
Expand Down
1 change: 1 addition & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
<orderEntry type="library" exported="" name="glide-3.6.1" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="module" module-name="banner-banner" exported="" />
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "com.test.banner"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/test/banner/Banner2Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protected void onCreate(Bundle savedInstanceState) {
banner.setBannerTitle(titles);
//设置轮播间隔时间
banner.setDelayTime(3000);
//设置动画
banner.setBannerAnimation(BannerConfig.ROTATEDOWN);
/**
* 可以选择设置图片网址,或者资源文件,默认用Glide加载
* 如果你想设置默认图片就在xml里设置default_image
Expand Down
22 changes: 10 additions & 12 deletions banner/banner-banner.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":banner" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.youth.banner" external.system.module.version="1.2.6" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":banner" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.youth.banner" external.system.module.version="1.2.7" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -64,14 +64,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
Expand All @@ -80,7 +72,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
Expand All @@ -96,9 +95,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
Expand All @@ -107,6 +104,7 @@
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="glide-3.6.1" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
</component>
Expand Down
9 changes: 5 additions & 4 deletions banner/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
version = "1.2.6"
version = "1.2.7"

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
minSdkVersion 14
minSdkVersion 11
targetSdkVersion 23
versionCode 20
versionName "1.2.6"
versionCode 21
versionName "1.2.7"
}
buildTypes {
release {
Expand All @@ -26,6 +26,7 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.nineoldandroids:library:2.4.0'
}


Expand Down
19 changes: 19 additions & 0 deletions banner/src/main/java/com/youth/banner/Banner.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.youth.banner.transformer.DepthPageTransformer;
import com.youth.banner.transformer.RotateDownPageTransformer;
import com.youth.banner.transformer.ZoomOutPageTransformer;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -147,6 +150,22 @@ public void setIndicatorGravity(int type) {
public void setBannerTitleList(List<String> titles) {
setBannerTitle(titles.toArray(new String[titles.size()]));
}
public void setBannerAnimation(int type) {
switch (type){
case BannerConfig.ZOOMOUT:
setPageTransformer(true,new ZoomOutPageTransformer());
break;
case BannerConfig.DEPTH:
setPageTransformer(true,new DepthPageTransformer());
break;
case BannerConfig.ROTATEDOWN:
setPageTransformer(true,new RotateDownPageTransformer());
break;
}
}
public void setPageTransformer(boolean reverseDrawingOrder, ViewPager.PageTransformer transformer){
viewPager.setPageTransformer(reverseDrawingOrder,transformer);
}
public void setBannerTitle(String[] titles) {
this.titles=titles;
if (bannerStyle==BannerConfig.CIRCLE_INDICATOR_TITLE||
Expand Down
19 changes: 18 additions & 1 deletion banner/src/main/java/com/youth/banner/BannerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,38 @@


public class BannerConfig {
/**
* indicator style
*/
public static final int NOT_INDICATOR=0;
public static final int CIRCLE_INDICATOR=1;
public static final int NUM_INDICATOR=2;
public static final int NUM_INDICATOR_TITLE=3;
public static final int CIRCLE_INDICATOR_TITLE=4;
public static final int CIRCLE_INDICATOR_TITLE_INSIDE=5;
/**
* indicator gravity
*/
public static final int LEFT=5;
public static final int CENTER=6;
public static final int RIGHT=7;

/**
* Animation
*/
public static final int ZOOMOUT=10;
public static final int DEPTH=11;
public static final int ROTATEDOWN=12;
/**
* banner
*/
public static final int INDICATOR_SIZE=8;
public static final int PADDING_SIZE=5;
public static final int TIME=2000;
public static final boolean IS_AUTO_PLAY=true;

/**
* title style
*/
public static final int TITLE_BACKGROUND=-1;
public static final int TITLE_HEIGHT=-1;
public static final int TITLE_TEXT_COLOR=-1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.youth.banner.transformer;

import android.support.v4.view.ViewPager;
import android.view.View;

public class DepthPageTransformer implements ViewPager.PageTransformer {
private static float MIN_SCALE = 0.75f;
@Override
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);
} else if (position <= 0) { // [-1,0]
// Use the default slide transition when
// moving to the left page
view.setAlpha(1);
view.setTranslationX(0);
view.setScaleX(1);
view.setScaleY(1);
} else if (position <= 1) { // (0,1]
// Fade the page out.
view.setAlpha(1 - position);
// Counteract the default slide transition
view.setTranslationX(pageWidth * -position);
// Scale the page down (between MIN_SCALE and 1)
float scaleFactor = MIN_SCALE + (1 - MIN_SCALE)
* (1 - Math.abs(position));
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);
} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.youth.banner.transformer;

import android.support.v4.view.ViewPager;
import android.view.View;

import com.nineoldandroids.view.ViewHelper;

public class RotateDownPageTransformer implements ViewPager.PageTransformer {
private static final float ROT_MAX = 20.0f;
private float mRot;


public void transformPage(View view, float position) {


if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
ViewHelper.setRotation(view, 0);

} else if (position <= 1) // a页滑动至b页 ; a页从 0.0 ~ -1 ;b页从1 ~ 0.0
{ // [-1,1]
// Modify the default slide transition to shrink the page as well
if (position < 0) {

mRot = (ROT_MAX * position);
ViewHelper.setPivotX(view, view.getMeasuredWidth() * 0.5f);
ViewHelper.setPivotY(view, view.getMeasuredHeight());
ViewHelper.setRotation(view, mRot);
} else {

mRot = (ROT_MAX * position);
ViewHelper.setPivotX(view, view.getMeasuredWidth() * 0.5f);
ViewHelper.setPivotY(view, view.getMeasuredHeight());
ViewHelper.setRotation(view, mRot);
}

// Scale the page down (between MIN_SCALE and 1)

// Fade the page relative to its size.

} else { // (1,+Infinity]
// This page is way off-screen to the right.
ViewHelper.setRotation(view, 0);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.youth.banner.transformer;

import android.support.v4.view.ViewPager;
import android.view.View;

public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
private static float MIN_SCALE = 0.85f;

private static float MIN_ALPHA = 0.5f;

@Override
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();

if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);
} else if (position <= 1) { // [-1,1]
// Modify the default slide transition to
// shrink the page as well
float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
float vertMargin = pageHeight * (1 - scaleFactor) / 2;
float horzMargin = pageWidth * (1 - scaleFactor) / 2;
if (position < 0) {
view.setTranslationX(horzMargin - vertMargin / 2);
} else {
view.setTranslationX(-horzMargin + vertMargin / 2);
}
// Scale the page down (between MIN_SCALE and 1)
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);
// Fade the page relative to its size.
view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE)
/ (1 - MIN_SCALE) * (1 - MIN_ALPHA));
} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ buildscript {
}
dependencies {

classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Apr 26 15:55:03 CST 2016
#Wed Aug 24 15:56:37 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

0 comments on commit 86b4d2c

Please sign in to comment.