码迷,mamicode.com
首页 > 移动开发 > 详细

Android-Activity跳转时动画

时间:2018-12-25 15:15:28      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:center   anim   star   参数   div   gre   启动   2.x   androi   

Activity跳转时动画,是在跳转Activity,或者在Activity结束返回 等,用到的进入效果;

 

第一种效果展示:

技术分享图片

 

第一个Activity的代码:

package liudeli.activity.activity_anim;

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

import liudeli.activity.R;

public class MyActivity01 extends Activity {

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

    /**
     * 启动另外一个Activity
     * @param view
     */
    public void startNewActivity(View view) {
        startActivity(new Intent(this, MyActivity02.class));
        /**
         * 参数一:新的Activity MyActivity02 进入时的动画...
         * 参数二:当前自己的Activity 动起来的动画
         */
        overridePendingTransition(R.anim.activity_open,0);
    }
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="启动另外一个Activity"
        android:onClick="startNewActivity"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="第一个Activity"
        android:layout_centerInParent="true"
        android:textSize="22dp"
        />

</RelativeLayout>

 

第二个Activity代码:

package liudeli.activity.activity_anim;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import liudeli.activity.R;

public class MyActivity02 extends Activity {

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

    /**
     * 结束自己
     * @param view
     */
    public void exitThisActivity(View view) {
        finish();
    }

    @Override
    public void finish() {
        super.finish();

        /**
         * 参数一:新的Activity MyActivity02 进入时的动画...
         * 参数二:当前自己的Activity 动起来的动画
         */
        overridePendingTransition(R.anim.activity_open, R.anim.activity_close);
    }
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00f000">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="结束自己"
        android:onClick="exitThisActivity"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="第二个Activity"
        android:layout_centerInParent="true"
        android:textSize="22dp"
        />

</RelativeLayout>

 

技术分享图片

R.anim.activity_open.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="-100%p"
        android:toXDelta="0"
        android:duration="1500"
        />
</set>

R.anim.activity_close.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="0"
        android:toXDelta="100%p"
        android:duration="1500"
        />
</set>

 


 

 

第二种效果展示:

技术分享图片

 

第一个Activity代码:

package liudeli.activity.activity_anim;

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

import liudeli.activity.R;

public class MyActivity01 extends Activity {

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

    /**
     * 启动另外一个Activity
     * @param view
     */
    public void startNewActivity(View view) {
        startActivity(new Intent(this, MyActivity02.class));
        /**
         * 参数一:新的Activity MyActivity02 进入时的动画...
         * 参数二:当前自己的Activity 动起来的动画
         */
        overridePendingTransition(R.anim.activity_open02,R.anim.activity_close02);
    }
}

 

第二个Activity代码:

package liudeli.activity.activity_anim;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import liudeli.activity.R;

public class MyActivity02 extends Activity {

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

    /**
     * 结束自己
     * @param view
     */
    public void exitThisActivity(View view) {
        finish();
    }

    @Override
    public void finish() {
        super.finish();

        /**
         * 参数一:新的Activity MyActivity02 进入时的动画...
         * 参数二:当前自己的Activity 动起来的动画
         */
        overridePendingTransition(R.anim.activity_open02, R.anim.activity_close02);
    }
}

 

R.anim.activity_open02.xml

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

    <translate android:fromYDelta="-100%p"
               android:toYDelta="0"
               android:duration="2500"
        />
</set>

R.anim.activity_close02.xml

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

    <translate android:fromYDelta="0"
               android:toYDelta="100%p"
               android:duration="2500"
        />
</set>

 


 

 

第三种效果展示:

技术分享图片

 

第一个Activity的代码:

package liudeli.activity.activity_anim;

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

import liudeli.activity.R;

public class MyActivity01 extends Activity {

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

    /**
     * 启动另外一个Activity
     * @param view
     */
    public void startNewActivity(View view) {
        startActivity(new Intent(this, MyActivity02.class));
        /**
         * 参数一:新的Activity MyActivity02 进入时的动画...
         * 参数二:当前自己的Activity 动起来的动画
         */
        overridePendingTransition(R.anim.activity_open02, 0);
    }
}

 

第二个Activity的代码:

package liudeli.activity.activity_anim;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import liudeli.activity.R;

public class MyActivity02 extends Activity {

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

    /**
     * 结束自己
     * @param view
     */
    public void exitThisActivity(View view) {
        finish();
    }

    @Override
    public void finish() {
        super.finish();

        /**
         * 参数一:新的Activity MyActivity02 进入时的动画...
         * 参数二:当前自己的Activity 动起来的动画
         */
        overridePendingTransition(R.anim.activity_open03, 0);
    }
}

 

R.anim.activity_open02.xml

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

    <translate android:fromYDelta="-100%p"
               android:toYDelta="0"
               android:duration="2500"
        />

</set>

R.anim.activity_open03.xml

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

    <translate android:fromYDelta="100%p"
               android:toYDelta="0"
               android:duration="2500"
        />

</set>

 


 

 

第四种效果展示:

技术分享图片

 

第一个Activity的代码:

package liudeli.activity.activity_anim;

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

import liudeli.activity.R;

public class MyActivity01 extends Activity {

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

    /**
     * 启动另外一个Activity
     * @param view
     */
    public void startNewActivity(View view) {
        startActivity(new Intent(this, MyActivity02.class));
        /**
         * 参数一:新的Activity MyActivity02 进入时的动画...
         * 参数二:当前自己的Activity 动起来的动画
         */
        overridePendingTransition(R.anim.activity_open_anim, 0);
    }
}

 

第二个Activity的代码:

package liudeli.activity.activity_anim;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import liudeli.activity.R;

public class MyActivity02 extends Activity {

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

    /**
     * 结束自己
     * @param view
     */
    public void exitThisActivity(View view) {
        finish();
    }

    @Override
    public void finish() {
        super.finish();

        /**
         * 参数一:新的Activity MyActivity02 进入时的动画...
         * 参数二:当前自己的Activity 动起来的动画
         */
        overridePendingTransition(R.anim.activity_open_anim, 0);
    }
}

 

R.anim.activity_open_anim.xml

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

    <alpha android:fromAlpha="0"
           android:toAlpha="1"
           android:duration="3600"/>

</set>

 


 

 

第五种效果展示:

技术分享图片

 

第一个Activity代码:

package liudeli.activity.activity_anim;

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

import liudeli.activity.R;

public class MyActivity01 extends Activity {

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

    /**
     * 启动另外一个Activity
     * @param view
     */
    public void startNewActivity(View view) {
        startActivity(new Intent(this, MyActivity02.class));
        /**
         * 参数一:新的Activity MyActivity02 进入时的动画...
         * 参数二:当前自己的Activity 动起来的动画
         */
        overridePendingTransition(R.anim.activity_open_anim02, R.anim.activity_close_anim02);
    }
}

 

第二个Activity代码:

package liudeli.activity.activity_anim;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import liudeli.activity.R;

public class MyActivity02 extends Activity {

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

    /**
     * 结束自己
     * @param view
     */
    public void exitThisActivity(View view) {
        finish();
    }

    @Override
    public void finish() {
        super.finish();

        /**
         * 参数一:新的Activity MyActivity02 进入时的动画...
         * 参数二:当前自己的Activity 动起来的动画
         */
        overridePendingTransition(R.anim.activity_open_anim02, R.anim.activity_close_anim02);
    }
}

 

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

    <rotate android:fromDegrees="180"
            android:toDegrees="0"
            android:duration="2000"
        />

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

    <rotate android:fromDegrees="0"
            android:toDegrees="-180"
            android:duration="2000"
        />

</set>

 

Android-Activity跳转时动画

标签:center   anim   star   参数   div   gre   启动   2.x   androi   

原文地址:https://www.cnblogs.com/android-deli/p/10173791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!