欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

android Activity打开和关闭动画

程序员文章站 2024-01-06 16:39:46
activity 之间的动画跳转,或者是关闭的的时候的动画关闭。public class SActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_s); f...

activity 之间的动画跳转,或者是关闭的的时候的动画关闭。

public class SActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_s);
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                intentTo();
            }
        });
    }

    private void intentTo() {
        Intent intent = new Intent(SActivity.this, MActivity.class);
        startActivity(intent);

        //从上向下打开页面
//        overridePendingTransition(R.anim.anim_top_in, R.anim.anim_bottom_out);

        //从右向左打开页面
//        overridePendingTransition(R.anim.anim_right_in,R.anim.anim_left_out);

        //从左向右打开页面
//        overridePendingTransition(R.anim.anim_left_in,R.anim.anim_right_out);

        //从下向上打开页面
        overridePendingTransition(R.anim.anim_bottom_in, R.anim.anim_top_out);
    }
}
public class MActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_m);
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MActivity.this.finish();
            }
        });
    }

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

        //从下向上弹出关闭页面
//        overridePendingTransition(R.anim.anim_bottom_in, R.anim.anim_top_out);

        //从左向右弹出关闭页面
//        overridePendingTransition(R.anim.anim_left_in, R.anim.anim_right_out);

        //从右向左弹出关闭页面
//        overridePendingTransition(R.anim.anim_right_in, R.anim.anim_left_out);

        //从上向下弹出关闭页面
        overridePendingTransition(R.anim.anim_top_in, R.anim.anim_bottom_out);
    }
}

 

这其中的动画文件是:

anim_bottom_in.xml
 

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate
        android:duration="250"
        android:fromYDelta="100%p"
        android:toYDelta="0%p" />
</set>

anim_bottom_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate
        android:duration="250"
        android:fromYDelta="0%p"
        android:toYDelta="100%p" />
</set>

anim_left_in.xml

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

anim_left_out.xml

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

anim_right_in.xml

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

anim_right_out.xml

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

anim_top_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate
        android:duration="250"
        android:fromYDelta="-100%p"
        android:toYDelta="0%p" />
</set>

anim_top_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate
        android:duration="250"
        android:fromYDelta="0%p"
        android:toYDelta="-100%p" />

</set>

 

 

 

本文地址:https://blog.csdn.net/WY1605058341/article/details/107516346