欢迎界面 WelcomeActivity .java
public class WelcomeActivity extends Activity implements AnimationListener {
private ImageView imageView = null;
private Animation alphaAnimation = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
imageView = (ImageView)findViewById(R.id.welcome_image_view);
alphaAnimation = AnimationUtils.loadAnimation(this, R.anim.welcome_alpha);
alphaAnimation.setFillEnabled(true); //启动Fill保持
alphaAnimation.setFillAfter(true); //设置动画的最后一帧是保持在View上面
imageView.setAnimation(alphaAnimation);
alphaAnimation.setAnimationListener(this); //为动画设置监听
}
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//动画结束时结束欢迎界面并转到软件的主界面
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
this.finish();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
//在欢迎界面屏蔽BACK键
if(keyCode==KeyEvent.KEYCODE_BACK) {
return false;
}
return false;
}
}
登录后的主界面MainActivity .java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
布局文件
welcome_alpha.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="2000"
/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="3000"
android:duration="3000"
/>
</set>
welcome.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_vertical|center_horizontal">
<ImageView
android:id="@+id/welcome_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/welcome"
/>
</LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="软件主界面" />
</LinearLayout>