Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hongyangAndroid committed May 7, 2016
1 parent f866684 commit f338d87
Show file tree
Hide file tree
Showing 53 changed files with 1,152 additions and 9 deletions.
25 changes: 16 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/captures

# Built application files
*.apk
*.ap_

# Files for the Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/

# Gradle files
.gradle/
build/
/build
/*/build/

# Local configuration file (sdk path, etc)
local.properties
Expand All @@ -25,8 +24,16 @@ proguard/
# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/
# Eclipse project files
.classpath
.project
.settings/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/

# Android Studio captures folder
captures/
# System files
.DS_Store
102 changes: 102 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,104 @@
# MagicViewPager
单页显示3个Item的ViewPager炫酷切换效果,适用于Banner等。

## 效果图

* Rotate Y

<img src="screenshot/rotate_y.gif" width="420px"/>


* Rotate Down

<img src="screenshot/rotate_down.gif" width="420px"/>

* Rotate Up

<img src="screenshot/rotate_up.gif" width="420px"/>

* Alpha

<img src="screenshot/alpha.gif" width="420px"/>

* ScaleIn

<img src="screenshot/scaleIn.gif" width="420px"/>


* ScaleIn + Alpha + Rotate Down

<img src="screenshot/zuhe.gif" width="420px"/>

## 使用

###(1)引入

```
compile `com.zhy:magic-viewpager:1.0.0`
```

###(2)示例

* 布局文件

```
<FrameLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:clipChildren="false"
android:layout_centerInParent="true"
android:background="#aadc71ff"
>
<android.support.v4.view.ViewPager
android:id="@+id/id_viewpager"
android:layout_width="match_parent"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:layout_height="120dp"
android:layout_gravity="center"
>
</android.support.v4.view.ViewPager>
</FrameLayout>
```
注意外层`android:layout_centerInParent="true"`.

* 编码

```
mViewPager.setPageMargin(20);//设置page间间距,自行根据需求设置
mViewPager.setOffscreenPageLimit(3);//>=3
mViewPager.setAdapter...//写法不变
//setPageTransformer 决定动画效果
mViewPager.setPageTransformer(true, new
RotateDownPageTransformer());
```



##目前可选动画

* AlphaPageTransformer
* RotateDownPageTransformer
* RotateUpPageTransformer
* RotateYTransformer
* NonPageTransformer
* ScaleInTransformer

其中AlphaPageTransformer、NonPageTransformer、单独使用,需要调用` mViewPager.setClipChildren(false);`,其余不用。

动画间可以自由组合,例如:

```
mViewPager.setPageTransformer(true,
new RotateDownPageTransformer(new AlphaPageTransformer(new ScaleInTransformer())));
```

##致谢

本文是我在审公众号投稿时,由本篇文章产生灵感:[Android超高仿QQ附近的人搜索展示(一)](http://mp.weixin.qq.com/s?__biz=MzAxMTI4MTkwNQ==&mid=2650820073&idx=1&sn=9e084723624180f7ab28e54f2aef132c&scene=23&srcid=0506b08maFirw2pBvnewcDsp#rd) ,ps:欢迎关注我的公众号。

除上文外编码过程中参考:

* http://blog.csdn.net/lmj623565791/article/details/40411921/
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
26 changes: 26 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "com.zhy.magicviewpager.sample"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile project(':library')
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/zhy/android/sdk/android-sdk-macosx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.zhy.magicviewpager;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application>
{
public ApplicationTest()
{
super(Application.class);
}
}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zhy.magicviewpager.sample" >

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
127 changes: 127 additions & 0 deletions app/src/main/java/com/zhy/magicviewpager/sample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.zhy.magicviewpager.sample;

import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.zhy.magicviewpager.transformer.AlphaPageTransformer;
import com.zhy.magicviewpager.transformer.NonPageTransformer;
import com.zhy.magicviewpager.transformer.RotateDownPageTransformer;
import com.zhy.magicviewpager.transformer.RotateUpPageTransformer;
import com.zhy.magicviewpager.transformer.RotateYTransformer;
import com.zhy.magicviewpager.transformer.ScaleInTransformer;

public class MainActivity extends AppCompatActivity
{

private ViewPager mViewPager;
private PagerAdapter mAdapter;

int[] imgRes = {R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d,
R.drawable.e, R.drawable.f, R.drawable.g, R.drawable.h, R.drawable.i};

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mViewPager = (ViewPager) findViewById(R.id.id_viewpager);

mViewPager.setPageMargin(20);
mViewPager.setOffscreenPageLimit(3);
mViewPager.setAdapter(mAdapter = new PagerAdapter()
{
@Override
public Object instantiateItem(ViewGroup container, int position)
{
ImageView view = new ImageView(MainActivity.this);
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
view.setLayoutParams(lp);
// view.setText(position + ":" + view);
view.setScaleType(ImageView.ScaleType.FIT_XY);
// view.setBackgroundColor(Color.parseColor("#44ff0000"));
view.setImageResource(imgRes[position]);
container.addView(view);
// view.setAdjustViewBounds(true);
return view;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object)
{
container.removeView((View) object);
}

@Override
public int getCount()
{
return imgRes.length;
}

@Override
public boolean isViewFromObject(View view, Object o)
{
return view == o;
}
});


mViewPager.setPageTransformer(true, new RotateDownPageTransformer());

}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
String[] effects = this.getResources().getStringArray(R.array.magic_effect);
for (String effect : effects)
menu.add(effect);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
String title = item.getTitle().toString();
mViewPager.setAdapter(mAdapter);

if ("RotateDown".equals(title))
{
mViewPager.setPageTransformer(true, new RotateDownPageTransformer());
} else if ("RotateUp".equals(title))
{
mViewPager.setPageTransformer(true, new RotateUpPageTransformer());
} else if ("RotateY".equals(title))
{
mViewPager.setPageTransformer(true, new RotateYTransformer());
} else if ("Standard".equals(title))
{
mViewPager.setClipChildren(false);
mViewPager.setPageTransformer(true, NonPageTransformer.INSTANCE);
} else if ("Alpha".equals(title))
{
mViewPager.setClipChildren(false);
mViewPager.setPageTransformer(true, new AlphaPageTransformer());
} else if ("ScaleIn".equals(title))
{
mViewPager.setPageTransformer(true, new ScaleInTransformer());
} else if ("RotateDown and Alpha".equals(title))
{
mViewPager.setPageTransformer(true, new RotateDownPageTransformer(new AlphaPageTransformer()));
}else if ("RotateDown and Alpha And ScaleIn".equals(title))
{
mViewPager.setPageTransformer(true, new RotateDownPageTransformer(new AlphaPageTransformer(new ScaleInTransformer())));
}

setTitle(title);

return true;
}
}
Binary file added app/src/main/res/drawable-xxhdpi/a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/e.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/f.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/g.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/h.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/i.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:clipChildren="false"
android:layout_centerInParent="true"
android:background="#aadc71ff"
>
<android.support.v4.view.ViewPager
android:id="@+id/id_viewpager"
android:layout_width="match_parent"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:layout_height="120dp"
android:layout_gravity="center"
>
</android.support.v4.view.ViewPager>

</FrameLayout>

</RelativeLayout>
Loading

0 comments on commit f338d87

Please sign in to comment.