Activity切换动画特效库--SwitchLayout

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

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

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


下面根据Demo说下大致的用法:

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以上即可


贴一下activity_main.xml的代码:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#1E90FF">
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context="com.example.dpl.switchlayoutdemo.MainActivity">

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="20dp"
        android:textColor="#ffffff"
        android:text="                      欢迎体验SwitchLayout特效动画"/>

    <Button
        android:id="@+id/btn_ok"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="3D翻转"/>
    <Button
        android:id="@+id/btn_1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="底部滑入" />

    <Button
        android:id="@+id/btn_2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="顶部滑入" />

    <Button
        android:id="@+id/btn_3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="左侧滑入" />

    <Button
        android:id="@+id/btn_4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="右侧滑入" />

    <Button
        android:id="@+id/btn_5"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="淡入淡出" />

    <Button
        android:id="@+id/btn_6"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="中心缩放" />

    <Button
        android:id="@+id/btn_7"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="上下翻转" />

    <Button
        android:id="@+id/btn_8"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="左上角缩放" />

    <Button
        android:id="@+id/btn_9"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="震动模式" />

    <Button
        android:id="@+id/btn_10"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="左侧中心旋转" />

    <Button
        android:id="@+id/btn_11"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="左上角旋转" />

    <Button
        android:id="@+id/btn_12"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="中心旋转" />

    <Button
        android:id="@+id/btn_13"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="横向展开" />

    <Button
        android:id="@+id/btn_14"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="纵向展开" />
  </LinearLayout>
</ScrollView>

第二个页面标题的子title_pressed.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="@color/title_bg_pressed" />

</shape>

第二个页面标题的子title_normal.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="@color/title_bg" />

</shape>


第二个页面标题的选择title_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/title_pressed" android:state_pressed="true"></item>
    <item android:drawable="@drawable/title_normal"></item>

</selector>


配置文件colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="white">#ffffff</color>
    <color name="transparent">#00000000</color>
    <color name="text_color">#191919</color>
    <color name="text_color_light">#7e7e7e</color>
    <color name="diliver">#c7c8c8</color>
    <color name="global_bg">#fbfcfc</color>
    <color name="title_bg">#37bcb2</color>
    <color name="title_bg_pressed">#99dcd7</color>

</resources>



贴一下第二个activity_second.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="45dp"
        android:background="@color/title_bg" >

        <ImageView
            android:id="@+id/iv_back"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:background="@drawable/title_selector"
            android:padding="10dp"
            android:src="@drawable/icon_back" />

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="45dp"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:singleLine="true"
            android:text="来,开饭!"
            android:textColor="@color/white" />

        <ImageView
            android:id="@+id/iv_more"
            android:layout_width="wrap_content"
            android:layout_height="45dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:background="@drawable/title_selector"
            android:gravity="center"
            android:padding="10dp"
            android:src="@drawable/icon_more" />
    </RelativeLayout>
    <ImageView
        android:src="@drawable/food"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

MainActivity代码:
package com.example.dpl.switchlayoutdemo;
import android.app.Activity;  
import android.content.Intent;  
import android.os.Bundle;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.view.Window;  
import android.widget.Button;  
  
import com.tandong.swichlayout.BaseEffects;  
import com.tandong.swichlayout.SwitchLayout;  
  
/** 
 * SwitchLayout 
 * 如果想自定义特效动画时长的话,请在此四个变量对应设置 SwitchLayout.animDuration = 1000; 
 * SwitchLayout.longAnimDuration = 2000; BaseAnimViewS.animDuration = 1000; 
 * BaseAnimViewS.longAnimDuration = 2000;即可。单位毫秒。  
 */  
public class MainActivity extends Activity {  
    private Button btn_ok, btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_7,  
            btn_8, btn_9, btn_10, btn_11, btn_12, btn_13, btn_14;  
  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        requestWindowFeature(Window.FEATURE_NO_TITLE);  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
        initView();  
  
        // 设置进入Activity的Activity特效动画,同理可拓展为布局动画  
        SwitchLayout.getSlideFromBottom(this, false,  
                BaseEffects.getQuickToSlowEffect());  
        // 三个参数分别为(Activity/View,是否关闭Activity,特效(可为空))  
        initListener();  
  
    }  
  
    private void initListener() {  
        btn_ok.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 0);  
                MainActivity.this.startActivity(in);  
            }  
        });  
  
        btn_1.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 1);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_2.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 2);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_3.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 3);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_4.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 4);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_5.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 5);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_6.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 6);  
                MainActivity.this.startActivity(in);  
            }  
        });  
  
        btn_7.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 7);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_8.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 8);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_9.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 9);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_10.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 10);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_11.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 11);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_12.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 12);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_13.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 13);  
                MainActivity.this.startActivity(in);  
            }  
        });  
        btn_14.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                // TODO Auto-generated method stub  
                Intent in = new Intent(MainActivity.this, SecondActivity.class);  
                in.putExtra("key", 14);  
                MainActivity.this.startActivity(in);  
            }  
        });  
    }  
  
    private void initView() {  
        btn_ok = (Button) this.findViewById(R.id.btn_ok);  
        btn_1 = (Button) this.findViewById(R.id.btn_1);  
        btn_2 = (Button) this.findViewById(R.id.btn_2);  
        btn_3 = (Button) this.findViewById(R.id.btn_3);  
        btn_4 = (Button) this.findViewById(R.id.btn_4);  
        btn_5 = (Button) this.findViewById(R.id.btn_5);  
        btn_6 = (Button) this.findViewById(R.id.btn_6);  
        btn_7 = (Button) this.findViewById(R.id.btn_7);  
        btn_8 = (Button) this.findViewById(R.id.btn_8);  
        btn_9 = (Button) this.findViewById(R.id.btn_9);  
        btn_10 = (Button) this.findViewById(R.id.btn_10);  
        btn_11 = (Button) this.findViewById(R.id.btn_11);  
        btn_12 = (Button) this.findViewById(R.id.btn_12);  
        btn_13 = (Button) this.findViewById(R.id.btn_13);  
        btn_14 = (Button) this.findViewById(R.id.btn_14);  
  
    }  
}  

SecondActivity.java的代码:
package com.example.dpl.switchlayoutdemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;

import com.tandong.swichlayout.BaseEffects;
import com.tandong.swichlayout.SwichLayoutInterFace;
import com.tandong.swichlayout.SwitchLayout;
public class SecondActivity extends Activity implements SwichLayoutInterFace {  
    private Intent intent;  
    private ImageView iv_back;  
    private int key = 0;  
  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        requestWindowFeature(Window.FEATURE_NO_TITLE);  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_second);  
        initIntent();  
        // 设置进入Activity的Activity特效动画,同理可拓展为布局动画  
        setEnterSwichLayout();  
    }  
  
    private void initIntent() {  
        intent = getIntent();  
        key = intent.getExtras().getInt("key");  
        iv_back = (ImageView) this.findViewById(R.id.iv_back);  
        iv_back.setOnClickListener(new OnClickListener() {  
  
            @Override  
            public void onClick(View arg0) {  
                setExitSwichLayout();  
            }  
        });  
    }  
  
    public boolean onKeyDown(int keyCode, KeyEvent event) {// 按返回键时退出Activity的Activity特效动画  
  
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {  
            setExitSwichLayout();  
            return true;  
        }  
        return super.onKeyDown(keyCode, event);  
    }  
  
    @Override  
    public void setEnterSwichLayout() {  
        switch (key) {  
        case 0:  
            SwitchLayout.get3DRotateFromLeft(this, false, null);  
            // 三个参数分别为(Activity/View,是否关闭Activity,特效(可为空))  
            break;  
        case 1:  
            SwitchLayout.getSlideFromBottom(this, false,  
                    BaseEffects.getMoreSlowEffect());  
            break;  
        case 2:  
            SwitchLayout.getSlideFromTop(this, false,  
                    BaseEffects.getReScrollEffect());  
            break;  
        case 3:  
            SwitchLayout.getSlideFromLeft(this, false,  
                    BaseEffects.getLinearInterEffect());  
            break;  
        case 4:  
            SwitchLayout.getSlideFromRight(this, false, null);  
            break;  
        case 5:  
            SwitchLayout.getFadingIn(this);  
            break;  
        case 6:  
            SwitchLayout.ScaleBig(this, false, null);  
            break;  
        case 7:  
            SwitchLayout.FlipUpDown(this, false,  
                    BaseEffects.getQuickToSlowEffect());  
            break;  
        case 8:  
            SwitchLayout.ScaleBigLeftTop(this, false, null);  
            break;  
        case 9:  
            SwitchLayout.getShakeMode(this, false, null);  
            break;  
        case 10:  
            SwitchLayout.RotateLeftCenterIn(this, false, null);  
            break;  
        case 11:  
            SwitchLayout.RotateLeftTopIn(this, false, null);  
            break;  
        case 12:  
            SwitchLayout.RotateCenterIn(this, false, null);  
            break;  
        case 13:  
            SwitchLayout.ScaleToBigHorizontalIn(this, false, null);  
            break;  
        case 14:  
            SwitchLayout.ScaleToBigVerticalIn(this, false, null);  
            break;  
        default:  
            break;  
        }  
  
    }  
  
    @Override  
    public void setExitSwichLayout() {  
        switch (key) {  
        case 0:  
            SwitchLayout.get3DRotateFromRight(this, true, null);  
            break;  
        case 1:  
            SwitchLayout.getSlideToBottom(this, true,  
                    BaseEffects.getMoreSlowEffect());  
            break;  
        case 2:  
            SwitchLayout.getSlideToTop(this, true,  
                    BaseEffects.getReScrollEffect());  
            break;  
        case 3:  
            SwitchLayout.getSlideToLeft(this, true,  
                    BaseEffects.getLinearInterEffect());  
            break;  
        case 4:  
            SwitchLayout.getSlideToRight(this, true, null);  
            break;  
        case 5:  
            SwitchLayout.getFadingOut(this, true);  
            break;  
        case 6:  
            SwitchLayout.ScaleSmall(this, true, null);  
            break;  
        case 7:  
            SwitchLayout.FlipUpDown(this, true,  
                    BaseEffects.getQuickToSlowEffect());  
            break;  
        case 8:  
            SwitchLayout.ScaleSmallLeftTop(this, true, null);  
            break;  
        case 9:  
            SwitchLayout.getShakeMode(this, true, null);  
            break;  
        case 10:  
            SwitchLayout.RotateLeftCenterOut(this, true, null);  
            break;  
        case 11:  
            SwitchLayout.RotateLeftTopOut(this, true, null);  
            break;  
        case 12:  
            SwitchLayout.RotateCenterOut(this, true, null);  
            break;  
        case 13:  
            SwitchLayout.ScaleToBigHorizontalOut(this, true, null);  
            break;  
        case 14:  
            SwitchLayout.ScaleToBigVerticalOut(this, true, null);  
            break;  
        default:  
            break;  
        }  
  
    }  
  
}  

AndroidManifest.xml中的代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dpl.switchlayoutdemo">

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SecondActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:launchMode="singleTask">
        </activity>
    </application>
</manifest>
 

运行效果图:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值