Android动画设置
发表于|更新于
|阅读量:
Android开发中经常要设置动画,如下方法可以快速的设置动画.
定义动画xml
1 2 3 4 5 6 7 8 9 10 11 12 13
| <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="300" /> </set>
<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="300" /> </set>
|
然后,在Activity的onCreate()方法中,调用overridePendingTransition:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); }
@Override public void finish() { super.finish(); overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right); }
|