Home  >  Article  >  Web Front-end  >  Android page switching animation code implementation_html/css_WEB-ITnose

Android page switching animation code implementation_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:47:081212browse

1. Create a new anim package under project Src

Create anim package to store animation xml

2. Next step animation position animation

Explanation - 100% p p: represents Parent form, 100%: represents the entire form, -: the code moves to the left;
Move out the previous page: tran_out.xml (if you create it yourself, select translate)
<?xml version="1.0" encoding="utf-8"?><translate  xmlns:android="http://schemas.android.com/apk/res/android"    android:fromXDelta="0"    android:toXDelta="-100%p"    android:fromYDelta="0"    android:toYDelta="0"    android:duration="500"    >    </translate>
Enter the next page: Tran_in .xml
<?xml version="1.0" encoding="utf-8"?><translate  xmlns:android="http://schemas.android.com/apk/res/android"    android:fromXDelta="100%p"    android:toXDelta="0"    android:fromYDelta="0"    android:toYDelta="0"    android:duration="500"    ></translate>

3. Use animation:

Add in the method body executed under button onclike: overridePendingTransition(R.anim.tran_in, R.anim.tran_out);
//Two An activity switching effect can be placed after finish() or startActivity()

Similarly, attach the previous animation code
Tran_pre_out.xm;
<?xml version="1.0" encoding="utf-8"?><translate  xmlns:android="http://schemas.android.com/apk/res/android"    android:fromXDelta="0"    android:toXDelta="100%p"    android:fromYDelta="0"    android:toYDelta="0"    android:duration="500"    ></translate>
Tran_pre_in.xm
<?xml version="1.0" encoding="utf-8"?><translate  xmlns:android="http://schemas.android.com/apk/res/android"    android:fromXDelta="-100%p"    android:toXDelta="0"    android:fromYDelta="0"    android:toYDelta="0"    android:duration="500"    ></translate>
Use animation:
overridePendingTransition(R.anim.tran_pre_in, R.anim.tran_pre_out);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn