Android 界面淡出 淡入效果:
下面是一个工具类:
AnimFadeUtil.java
/** * 处理界面的淡入和淡出的切换 * @author Bruce * */ public class AnimFadeUtil { private static Handler handler = new Handler(){ public void handleMessage(Message msg) { View view = (View) msg.obj; //得到它的父元素 ViewGroup parent = (ViewGroup) view.getParent(); parent.removeView(view); }; }; /** * 淡出 * @param view 淡出的界面 * @param duration 淡出的时间 */ public static void fadeOut(final View view,long duration){ Animation animation = new AlphaAnimation(1, 0); animation.setDuration(duration); animation.setFillAfter(true);//设置第一个界面依然存在 animation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } /** * 淡出动画执行完毕 */ @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub Message message = Message.obtain(); message.obj = view; handler.sendMessage(message); } }); view.startAnimation(animation); } /** * * @param view * @param duration * @param delay 第一个界面淡出的时间 */ public static void fadeIn(View view,long duration ,long delay){ Animation animation = new AlphaAnimation(0,1); animation.setDuration(duration); animation.setStartOffset(delay); view.startAnimation(animation); }