業務開發時遇到的一個小特技,要求實現Activity啟動時自下向上彈出,退出時自上向下退出。
此處不關注啟動和退出時其他Activity的動畫效果,實現方法有兩種:
1.代碼方式,通過Activity的overridePendingTransition接口,
即在startActivity時調用overridePendingTransition(R.anim.push_bottom_in, 0)
在finish時調用overridePendingTransition(0, R.anim.push_bottom_out)
2.配置style, 具體做法如下:
1>在res/values/styles.xml中定義style:ActivityInOutAnimation
2>在res/values/themes.xml中定義Theme.BatchManageActivity
3>為目標activity設置theme,示例如下:
相比方案1,xml配置的方式可重用性更強,業務和UI分離,便於維護,建議采用方案2。
附上特技動畫:
push_bottom_in.xml
push_bottom_out.xml