0

Android的Activity切换动画特效库SwitchLayout,视图切换动画库,媲美IOS

由于看了IOS上面很多开发者开发的APP的视图界面切换动画体验非常好,这些都是IOS自带的,但是Android的Activity等视图切换动画并没有提供原生的,所以特此写了一个可以媲美IOS视图切换动画的Android视图切换动画特效库!SwitchLayout!可以说是目前Android上第一个,也是唯一的一个强大的视图切换动画库引擎!

作者:谭东

QQ:852041173

项目开源!推荐使用jar包形式!

没有经过作者允许,不可修改项目库源码自行发布。

如果你的项目中使用了SwtichLayout,建议你在您的APP关于页面注明SwitchLayout库提供支持!非常感谢!如果您觉得SwitchLayout强大,欢迎推荐给你们的朋友。

如果有什么建议,也可以反馈给我,会及时升级SwitchLayout库。

SwitchLayout 的1.0jar包下载地址和Demo下载地址:http://pan.baidu.com/s/1dD6baLV

源码和demo在github地址:https://github.com/jaychou2012/SwitchLayout

好了,先看下主要的界面支持的视图切换特效吧!(此为Demo截图)

效果引擎足够媲美IOS了。

里面的列表中,每个特效暴露的自定义扩展特效引擎接口大概可以扩充8个特效。所以一共大概可以扩充105种特效!足够强大!

好了,下面说下大致的用法:

1.导入SwitchLayout1.0.jar或者下载开源库。

2.每个Activity实现接口implements SwichLayoutInterFace。推荐这种用法;接口里分别实现2个方法:setEnterSwichLayout();和setExitSwichLayout();这两个方法分别是设置进入Activity动画和离开Activity的动画的。

在onCreate()里调用setEnterSwichLayout();  在关闭Activity操作里调用setExitSwichLayout(); 如果需要的话在onKeyDown里拦截返回按键,调用setExitSwichLayout();

3.具体特效调用(举一个例子): SwitchLayout.getSlideFromBottom(this, false,BaseEffects.getMoreSlowEffect());

// 三个参数分别为(Activity/View,是否关闭Activity,特效(可为空));每个特效支持8种扩种,也可以不填特效。

4.注意,在项目注册清单里,每个Activity要设置主题为透明主题。 android:theme=”@android:style/Theme.Translucent”,API在11以上即可。

下面贴下SwitchLayoutDemo里的代码:

  1. package com.tandong.swichlayoutdemo;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.view.Window;
  8. import android.widget.Button;
  9. import com.tandong.swichlayout.BaseEffects;
  10. import com.tandong.swichlayout.SwitchLayout;
  11. /**
  12.  * SwitchLayout
  13.  * 
  14.  * QQ 852041173
  15.  * 
  16.  * 为Android提供IOS平台自有的界面视图切换动画而开发此库,工作量也不小,感谢支持SwitchLayout
  17.  * 
  18.  * 如果想自定义特效动画时长的话,请在此四个变量对应设置 SwitchLayout.animDuration = 1000;
  19.  * SwitchLayout.longAnimDuration = 2000; BaseAnimViewS.animDuration = 1000;
  20.  * BaseAnimViewS.longAnimDuration = 2000;即可。单位毫秒。
  21.  * 
  22.  * 以后SwitchLayout将会划分入我的SmartUI库下面
  23.  * 
  24.  * @author Tan Dong(谭东) 2014.12.28
  25.  * 
  26.  */
  27. public class MainActivity extends Activity {
  28.     private Button btn_ok, btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_7,
  29.             btn_8, btn_9, btn_10, btn_11, btn_12, btn_13, btn_14;
  30.     @Override
  31.     protected void onCreate(Bundle savedInstanceState) {
  32.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  33.         super.onCreate(savedInstanceState);
  34.         setContentView(R.layout.activity_main);
  35.         initView();
  36.         // 设置进入Activity的Activity特效动画,同理可拓展为布局动画
  37.         SwitchLayout.getSlideFromBottom(thisfalse,
  38.                 BaseEffects.getQuickToSlowEffect());
  39.         // 三个参数分别为(Activity/View,是否关闭Activity,特效(可为空))
  40.         initListener();
  41.     }
  42.     private void initListener() {
  43.         btn_ok.setOnClickListener(new OnClickListener() {
  44.             @Override
  45.             public void onClick(View arg0) {
  46.                 // TODO Auto-generated method stub
  47.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  48.                 in.putExtra(“key”0);
  49.                 MainActivity.this.startActivity(in);
  50.             }
  51.         });
  52.         btn_1.setOnClickListener(new OnClickListener() {
  53.             @Override
  54.             public void onClick(View arg0) {
  55.                 // TODO Auto-generated method stub
  56.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  57.                 in.putExtra(“key”1);
  58.                 MainActivity.this.startActivity(in);
  59.             }
  60.         });
  61.         btn_2.setOnClickListener(new OnClickListener() {
  62.             @Override
  63.             public void onClick(View arg0) {
  64.                 // TODO Auto-generated method stub
  65.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  66.                 in.putExtra(“key”2);
  67.                 MainActivity.this.startActivity(in);
  68.             }
  69.         });
  70.         btn_3.setOnClickListener(new OnClickListener() {
  71.             @Override
  72.             public void onClick(View arg0) {
  73.                 // TODO Auto-generated method stub
  74.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  75.                 in.putExtra(“key”3);
  76.                 MainActivity.this.startActivity(in);
  77.             }
  78.         });
  79.         btn_4.setOnClickListener(new OnClickListener() {
  80.             @Override
  81.             public void onClick(View arg0) {
  82.                 // TODO Auto-generated method stub
  83.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  84.                 in.putExtra(“key”4);
  85.                 MainActivity.this.startActivity(in);
  86.             }
  87.         });
  88.         btn_5.setOnClickListener(new OnClickListener() {
  89.             @Override
  90.             public void onClick(View arg0) {
  91.                 // TODO Auto-generated method stub
  92.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  93.                 in.putExtra(“key”5);
  94.                 MainActivity.this.startActivity(in);
  95.             }
  96.         });
  97.         btn_6.setOnClickListener(new OnClickListener() {
  98.             @Override
  99.             public void onClick(View arg0) {
  100.                 // TODO Auto-generated method stub
  101.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  102.                 in.putExtra(“key”6);
  103.                 MainActivity.this.startActivity(in);
  104.             }
  105.         });
  106.         btn_7.setOnClickListener(new OnClickListener() {
  107.             @Override
  108.             public void onClick(View arg0) {
  109.                 // TODO Auto-generated method stub
  110.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  111.                 in.putExtra(“key”7);
  112.                 MainActivity.this.startActivity(in);
  113.             }
  114.         });
  115.         btn_8.setOnClickListener(new OnClickListener() {
  116.             @Override
  117.             public void onClick(View arg0) {
  118.                 // TODO Auto-generated method stub
  119.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  120.                 in.putExtra(“key”8);
  121.                 MainActivity.this.startActivity(in);
  122.             }
  123.         });
  124.         btn_9.setOnClickListener(new OnClickListener() {
  125.             @Override
  126.             public void onClick(View arg0) {
  127.                 // TODO Auto-generated method stub
  128.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  129.                 in.putExtra(“key”9);
  130.                 MainActivity.this.startActivity(in);
  131.             }
  132.         });
  133.         btn_10.setOnClickListener(new OnClickListener() {
  134.             @Override
  135.             public void onClick(View arg0) {
  136.                 // TODO Auto-generated method stub
  137.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  138.                 in.putExtra(“key”10);
  139.                 MainActivity.this.startActivity(in);
  140.             }
  141.         });
  142.         btn_11.setOnClickListener(new OnClickListener() {
  143.             @Override
  144.             public void onClick(View arg0) {
  145.                 // TODO Auto-generated method stub
  146.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  147.                 in.putExtra(“key”11);
  148.                 MainActivity.this.startActivity(in);
  149.             }
  150.         });
  151.         btn_12.setOnClickListener(new OnClickListener() {
  152.             @Override
  153.             public void onClick(View arg0) {
  154.                 // TODO Auto-generated method stub
  155.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  156.                 in.putExtra(“key”12);
  157.                 MainActivity.this.startActivity(in);
  158.             }
  159.         });
  160.         btn_13.setOnClickListener(new OnClickListener() {
  161.             @Override
  162.             public void onClick(View arg0) {
  163.                 // TODO Auto-generated method stub
  164.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  165.                 in.putExtra(“key”13);
  166.                 MainActivity.this.startActivity(in);
  167.             }
  168.         });
  169.         btn_14.setOnClickListener(new OnClickListener() {
  170.             @Override
  171.             public void onClick(View arg0) {
  172.                 // TODO Auto-generated method stub
  173.                 Intent in = new Intent(MainActivity.this, SecondActivity.class);
  174.                 in.putExtra(“key”14);
  175.                 MainActivity.this.startActivity(in);
  176.             }
  177.         });
  178.     }
  179.     private void initView() {
  180.         btn_ok = (Button) this.findViewById(R.id.btn_ok);
  181.         btn_1 = (Button) this.findViewById(R.id.btn_1);
  182.         btn_2 = (Button) this.findViewById(R.id.btn_2);
  183.         btn_3 = (Button) this.findViewById(R.id.btn_3);
  184.         btn_4 = (Button) this.findViewById(R.id.btn_4);
  185.         btn_5 = (Button) this.findViewById(R.id.btn_5);
  186.         btn_6 = (Button) this.findViewById(R.id.btn_6);
  187.         btn_7 = (Button) this.findViewById(R.id.btn_7);
  188.         btn_8 = (Button) this.findViewById(R.id.btn_8);
  189.         btn_9 = (Button) this.findViewById(R.id.btn_9);
  190.         btn_10 = (Button) this.findViewById(R.id.btn_10);
  191.         btn_11 = (Button) this.findViewById(R.id.btn_11);
  192.         btn_12 = (Button) this.findViewById(R.id.btn_12);
  193.         btn_13 = (Button) this.findViewById(R.id.btn_13);
  194.         btn_14 = (Button) this.findViewById(R.id.btn_14);
  195.     }
  196. }

 

  1. package com.tandong.swichlayoutdemo;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.KeyEvent;
  6. import android.view.View;
  7. import android.view.View.OnClickListener;
  8. import android.view.Window;
  9. import android.widget.ImageView;
  10. import com.tandong.swichlayout.BaseEffects;
  11. import com.tandong.swichlayout.SwichLayoutInterFace;
  12. import com.tandong.swichlayout.SwitchLayout;
  13. import com.tandong.swichlayoutdemo.R;
  14. /**
  15.  * SwitchLayout
  16.  * 
  17.  * QQ 852041173
  18.  * 
  19.  * 为Android提供IOS平台自有的界面视图切换动画而开发此库,工作量也不小,感谢支持SwitchLayout
  20.  * 
  21.  * @author Tan Dong(谭东) 2014.12.28
  22.  * 
  23.  */
  24. public class SecondActivity extends Activity implements SwichLayoutInterFace {
  25.     private Intent intent;
  26.     private ImageView iv_back;
  27.     private int key = 0;
  28.     @Override
  29.     protected void onCreate(Bundle savedInstanceState) {
  30.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  31.         super.onCreate(savedInstanceState);
  32.         setContentView(R.layout.activity_second);
  33.         initIntent();
  34.         // 设置进入Activity的Activity特效动画,同理可拓展为布局动画
  35.         setEnterSwichLayout();
  36.     }
  37.     private void initIntent() {
  38.         intent = getIntent();
  39.         key = intent.getExtras().getInt(“key”);
  40.         iv_back = (ImageView) this.findViewById(R.id.iv_back);
  41.         iv_back.setOnClickListener(new OnClickListener() {
  42.             @Override
  43.             public void onClick(View arg0) {
  44.                 setExitSwichLayout();
  45.             }
  46.         });
  47.     }
  48.     public boolean onKeyDown(int keyCode, KeyEvent event) {// 按返回键时退出Activity的Activity特效动画
  49.         if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
  50.             setExitSwichLayout();
  51.             return true;
  52.         }
  53.         return super.onKeyDown(keyCode, event);
  54.     }
  55.     @Override
  56.     public void setEnterSwichLayout() {
  57.         switch (key) {
  58.         case 0:
  59.             SwitchLayout.get3DRotateFromLeft(thisfalsenull);
  60.             // 三个参数分别为(Activity/View,是否关闭Activity,特效(可为空))
  61.             break;
  62.         case 1:
  63.             SwitchLayout.getSlideFromBottom(thisfalse,
  64.                     BaseEffects.getMoreSlowEffect());
  65.             break;
  66.         case 2:
  67.             SwitchLayout.getSlideFromTop(thisfalse,
  68.                     BaseEffects.getReScrollEffect());
  69.             break;
  70.         case 3:
  71.             SwitchLayout.getSlideFromLeft(thisfalse,
  72.                     BaseEffects.getLinearInterEffect());
  73.             break;
  74.         case 4:
  75.             SwitchLayout.getSlideFromRight(thisfalsenull);
  76.             break;
  77.         case 5:
  78.             SwitchLayout.getFadingIn(this);
  79.             break;
  80.         case 6:
  81.             SwitchLayout.ScaleBig(thisfalsenull);
  82.             break;
  83.         case 7:
  84.             SwitchLayout.FlipUpDown(thisfalse,
  85.                     BaseEffects.getQuickToSlowEffect());
  86.             break;
  87.         case 8:
  88.             SwitchLayout.ScaleBigLeftTop(thisfalsenull);
  89.             break;
  90.         case 9:
  91.             SwitchLayout.getShakeMode(thisfalsenull);
  92.             break;
  93.         case 10:
  94.             SwitchLayout.RotateLeftCenterIn(thisfalsenull);
  95.             break;
  96.         case 11:
  97.             SwitchLayout.RotateLeftTopIn(thisfalsenull);
  98.             break;
  99.         case 12:
  100.             SwitchLayout.RotateCenterIn(thisfalsenull);
  101.             break;
  102.         case 13:
  103.             SwitchLayout.ScaleToBigHorizontalIn(thisfalsenull);
  104.             break;
  105.         case 14:
  106.             SwitchLayout.ScaleToBigVerticalIn(thisfalsenull);
  107.             break;
  108.         default:
  109.             break;
  110.         }
  111.     }
  112.     @Override
  113.     public void setExitSwichLayout() {
  114.         switch (key) {
  115.         case 0:
  116.             SwitchLayout.get3DRotateFromRight(thistruenull);
  117.             break;
  118.         case 1:
  119.             SwitchLayout.getSlideToBottom(thistrue,
  120.                     BaseEffects.getMoreSlowEffect());
  121.             break;
  122.         case 2:
  123.             SwitchLayout.getSlideToTop(thistrue,
  124.                     BaseEffects.getReScrollEffect());
  125.             break;
  126.         case 3:
  127.             SwitchLayout.getSlideToLeft(thistrue,
  128.                     BaseEffects.getLinearInterEffect());
  129.             break;
  130.         case 4:
  131.             SwitchLayout.getSlideToRight(thistruenull);
  132.             break;
  133.         case 5:
  134.             SwitchLayout.getFadingOut(thistrue);
  135.             break;
  136.         case 6:
  137.             SwitchLayout.ScaleSmall(thistruenull);
  138.             break;
  139.         case 7:
  140.             SwitchLayout.FlipUpDown(thistrue,
  141.                     BaseEffects.getQuickToSlowEffect());
  142.             break;
  143.         case 8:
  144.             SwitchLayout.ScaleSmallLeftTop(thistruenull);
  145.             break;
  146.         case 9:
  147.             SwitchLayout.getShakeMode(thistruenull);
  148.             break;
  149.         case 10:
  150.             SwitchLayout.RotateLeftCenterOut(thistruenull);
  151.             break;
  152.         case 11:
  153.             SwitchLayout.RotateLeftTopOut(thistruenull);
  154.             break;
  155.         case 12:
  156.             SwitchLayout.RotateCenterOut(thistruenull);
  157.             break;
  158.         case 13:
  159.             SwitchLayout.ScaleToBigHorizontalOut(thistruenull);
  160.             break;
  161.         case 14:
  162.             SwitchLayout.ScaleToBigVerticalOut(thistruenull);
  163.             break;
  164.         default:
  165.             break;
  166.         }
  167.     }
  168. }

 

  1. <?xml version=“1.0” encoding=“utf-8”?>
  2. <manifest xmlns:android=“http://schemas.android.com/apk/res/android”
  3.     package=“com.tandong.swichlayoutdemo”
  4.     android:versionCode=“1”
  5.     android:versionName=“1.0” >
  6.     <uses-sdk
  7.         android:minSdkVersion=“11”
  8.         android:targetSdkVersion=“19” />
  9.     <application
  10.         android:allowBackup=“true”
  11.         android:icon=“@drawable/ic_launcher”
  12.         android:label=“@string/app_name”
  13.         android:theme=“@style/AppTheme” >
  14.         <activity
  15.             android:name=“com.tandong.swichlayoutdemo.MainActivity”
  16.             android:label=“@string/app_name”
  17.             android:theme=“@android:style/Theme.Translucent” >
  18.             <intent-filter>
  19.                 <action android:name=“android.intent.action.MAIN” />
  20.                 <category android:name=“android.intent.category.LAUNCHER” />
  21.             </intent-filter>
  22.         </activity>
  23.         <activity
  24.             android:name=“com.tandong.swichlayoutdemo.SecondActivity”
  25.             android:launchMode=“singleTask”
  26.             android:theme=“@android:style/Theme.Translucent” >
  27.         </activity>
  28.     </application>
  29. </manifest>

 

天边的星星