├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── me │ │ └── payge │ │ └── viewflipanimator │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── me │ │ │ └── payge │ │ │ └── viewflipanimator │ │ │ ├── MainActivity.java │ │ │ └── lib │ │ │ └── ViewAnimUtils.java │ └── res │ │ ├── layout │ │ └── activity_main.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 │ └── me │ └── payge │ └── viewflipanimator │ └── ExampleUnitTest.java ├── build.gradle ├── flip-snapshot.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ViewFlipAnimator 2 | 一种超简单纯Java实现的卡片翻转效果 3 | 4 | # Snapshot 5 | 6 | 7 | # Java Code 8 | 9 | ``` 10 | /** 11 | * 水平翻转 12 | * @param view target 13 | * @param duration time 14 | * @param direction 只能传1或-1,1为从右开始翻转,-1位从左开始翻转 15 | * @return 动画集合 16 | */ 17 | public static AnimatorSet flip(View view, int duration, int direction) { 18 | if (direction != 1 && direction != -1) direction = 1; 19 | view.setCameraDistance(16000*view.getResources().getDisplayMetrics().density); 20 | AnimatorSet animSet = new AnimatorSet(); 21 | ObjectAnimator rotationY = new ObjectAnimator(); 22 | rotationY.setDuration(duration).setPropertyName("rotationY"); 23 | rotationY.setFloatValues(0, 90*direction); 24 | ObjectAnimator _rotationY = new ObjectAnimator(); 25 | _rotationY.setDuration(duration).setPropertyName("rotationY"); 26 | _rotationY.setFloatValues(-90*direction, 0); 27 | _rotationY.setStartDelay(duration); 28 | ObjectAnimator scale = new ObjectAnimator(); 29 | scale.setDuration(duration).setPropertyName("scaleY"); 30 | scale.setFloatValues(1, 0.94f); 31 | ObjectAnimator _scale = new ObjectAnimator(); 32 | _scale.setDuration(duration).setPropertyName("scaleY"); 33 | _scale.setFloatValues(0.94f, 1); 34 | _scale.setStartDelay(duration); 35 | animSet.setTarget(view); 36 | rotationY.setTarget(view); 37 | _rotationY.setTarget(view); 38 | scale.setTarget(view); 39 | _scale.setTarget(view); 40 | animSet.playTogether(rotationY, _rotationY, scale, _scale); 41 | animSet.start(); 42 | return animSet; 43 | } 44 | ``` 45 | # About me 46 | 微博:[@萧雾宇](http://weibo.com/payge) 47 | Gmail:xiepeijieapp@gmail.com 48 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "me.payge.viewflipanimator" 9 | minSdkVersion 14 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.2.0' 26 | } 27 | -------------------------------------------------------------------------------- /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:\IDE\Android\sdk/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/me/payge/viewflipanimator/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package me.payge.viewflipanimator; 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/me/payge/viewflipanimator/MainActivity.java: -------------------------------------------------------------------------------- 1 | package me.payge.viewflipanimator; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.view.WindowManager; 7 | 8 | import me.payge.viewflipanimator.lib.ViewAnimUtils; 9 | 10 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 11 | 12 | private static final int duration = 500; 13 | 14 | private View button; 15 | private View frame; 16 | private View front; 17 | private View back; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 23 | setContentView(R.layout.activity_main); 24 | button = findViewById(R.id.button); 25 | frame = findViewById(R.id.frame); 26 | front = findViewById(R.id.front); 27 | back = findViewById(R.id.back); 28 | button.setOnClickListener(this); 29 | } 30 | 31 | private void switchViewVisibility() { 32 | if (back.isShown()) { 33 | back.setVisibility(View.GONE); 34 | front.setVisibility(View.VISIBLE); 35 | } else { 36 | back.setVisibility(View.VISIBLE); 37 | front.setVisibility(View.GONE); 38 | } 39 | } 40 | 41 | @Override 42 | public void onClick(View v) { 43 | if (v == button) { 44 | int direction = 1; 45 | if (back.isShown()) { 46 | direction = -1; 47 | } 48 | ViewAnimUtils.flip(frame, duration, direction); 49 | frame.postDelayed(new Runnable() { 50 | @Override 51 | public void run() { 52 | switchViewVisibility(); 53 | } 54 | }, duration); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/me/payge/viewflipanimator/lib/ViewAnimUtils.java: -------------------------------------------------------------------------------- 1 | package me.payge.viewflipanimator.lib; 2 | 3 | import android.animation.AnimatorSet; 4 | import android.animation.ObjectAnimator; 5 | import android.view.View; 6 | 7 | /** 8 | * @author payge view动画工具类 9 | */ 10 | public class ViewAnimUtils { 11 | 12 | /** 13 | * 水平翻转 14 | * @param view target 15 | * @param duration time 16 | * @param direction 只能传1或-1,1为从左开始翻转,-1位从右开始翻转 17 | * @return 动画集合 18 | */ 19 | public static AnimatorSet flip(View view, int duration, int direction) { 20 | if (direction != 1 && direction != -1) direction = 1; 21 | view.setCameraDistance(16000*view.getResources().getDisplayMetrics().density); 22 | AnimatorSet animSet = new AnimatorSet(); 23 | ObjectAnimator rotationY = new ObjectAnimator(); 24 | rotationY.setDuration(duration).setPropertyName("rotationY"); 25 | rotationY.setFloatValues(0, -90*direction); 26 | ObjectAnimator _rotationY = new ObjectAnimator(); 27 | _rotationY.setDuration(duration).setPropertyName("rotationY"); 28 | _rotationY.setFloatValues(90*direction, 0); 29 | _rotationY.setStartDelay(duration); 30 | ObjectAnimator scale = new ObjectAnimator(); 31 | scale.setDuration(duration).setPropertyName("scaleY"); 32 | scale.setFloatValues(1, 0.94f); 33 | ObjectAnimator _scale = new ObjectAnimator(); 34 | _scale.setDuration(duration).setPropertyName("scaleY"); 35 | _scale.setFloatValues(0.94f, 1); 36 | _scale.setStartDelay(duration); 37 | animSet.setTarget(view); 38 | rotationY.setTarget(view); 39 | _rotationY.setTarget(view); 40 | scale.setTarget(view); 41 | _scale.setTarget(view); 42 | animSet.playTogether(rotationY, _rotationY, scale, _scale); 43 | animSet.start(); 44 | return animSet; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 |