slide up xml animation on change activity in andro

2019-03-18 05:47发布

问题:

I read the below link before posting this.

How to apply slide animation between two activities in Android?

I need to know how to make activity slideup xml animation. like what they have done for fadein and fadeout.

回答1:

for slide_in xml :

<translate 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:duration="@android:integer/config_longAnimTime" 
      android:fromXDelta="-100%p" 
      android:toXDelta="0%p">
</translate>

for slide_out xml:

<translate
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:duration="@android:integer/config_longAnimTime" 
      android:fromXDelta="0" 
      android:toXDelta="100%p">
</translate>

Java code :

Intent intent = new Intent(this, newActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);

put both xml files in res/anim folder.



回答2:

The accepted answer isn't what the question was asking, which is animations that slide up from the bottom and slide out from the top.

pull_up_from_bottom.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
 android:duration="@android:integer/config_longAnimTime" 
android:fromYDelta="100%"
android:toYDelta="0%" />

push_out_to_bottom.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%"
android:toYDelta="100%" />