标签:
最近在看 Jammendo代码,打算将学习过程简单的记录下来,下面开始第一篇:
打开Jammendo运行之后,出弹出一个对话框,跳过对话框之后,会有一个淡出界面跳转到首页效果的实现。那么这个效果是怎么实现的呢,其实就是Animation中动画淡出的效果——原理大概是layout不透明变成全透明这样一个原理。
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500" /> </set>
fromAlpha为动画起始透明度,toAlpha是动画结束透明度,duration顾名思义也就是动画持续时间,当然有淡出也会有淡入,编写原理差不多,网上有相关代码,也可以自己去查找一下,很简单。
OK,看完上面的动画xml文件之后。。下面开始看在Activity中代码应该如何编写
在这里,我利用Handler和Runnable实现简单的动画淡出效果,android中动画效果是基于Animation来实现的,简单的说下实现的淡出效果实现
1 public class SplashscreenActivity extends Activity { 2 private Animation endAnimation; 3 private Handler endAnimationHandler; 4 private Runnable endAnimationRunnable; 5 @Override 6 protected void onCreate(Bundle savedInstanceState) { 7 // TODO Auto-generated method stub 8 super.onCreate(savedInstanceState); 9 setContentView(R.layout.splashlayout); 10 endAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_out); 11 endAnimation.setFillAfter(true); 12 13 endAnimationHandler = new Handler(); 14 endAnimationRunnable = new Runnable() { 15 @Override 16 public void run() { 17 findViewById(R.id.splashlayout).startAnimation(endAnimation); 18 } 19 }; 20 21 endAnimation.setAnimationListener(new AnimationListener() { 22 @Override 23 public void onAnimationStart(Animation animation) { } 24 25 @Override 26 public void onAnimationRepeat(Animation animation) { } 27 28 @Override 29 public void onAnimationEnd(Animation animation) { 30 // HomeActivity.launch(SplashscreenActivity.this); 31 // SplashscreenActivity.this.finish(); 32 } 33 }); 34 35 endAnimationHandler.removeCallbacks(endAnimationRunnable); 36 endAnimationHandler.postDelayed(endAnimationRunnable, 2000); 37 } 38 39 }
endAnimationHandler = new Handler();
endAnimationRunnable = new Runnable() {
public void run() { findViewById(R.id.splashlayout).startAnimation(endAnimation); } };
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/splashlayout" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:id="@+id/splashtextview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello_world" ></TextView> </LinearLayout>
endAnimationHandler.removeCallbacks(endAnimationRunnable);
endAnimationHandler.postDelayed(endAnimationRunnable, 2000);
标签:
原文地址:http://www.cnblogs.com/cfyrwang/p/4396944.html