不用线程做Android软件欢迎界面,透明效果,完成后自动跳转
16lz
2021-01-25
最近在网上看到一些Android软件的欢迎界面做得都挺复杂的(个人觉得),因为一般都用到了线程,接着就想有没有简单一点的办法。然后就有了下文:
这个欢迎界面主要是借助Animation动画来实现的(效果如图),不需要用到线程。实现的方法很简单,为动画设置监听就可以了,在动画播放结束时结束欢迎界面并跳转到软件的主界面。
/** * 欢迎界面 * @author 小建枫叶 * */public class WelcomeActivity extends Activity implements AnimationListener {private ImageView imageView = null;private Animation alphaAnimation = null;@Overrideprotected 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); //为动画设置监听 }@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {//动画结束时结束欢迎界面并转到软件的主界面Intent intent = new Intent(this, MainActivity.class);startActivity(intent);this.finish();}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {//在欢迎界面屏蔽BACK键if(keyCode==KeyEvent.KEYCODE_BACK) {return false;}return false;}}
动画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" //延迟3秒再开始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>
更多相关文章
- Handler的使用方法――在子线程中更新界面 .
- 盛大资深软件工程师谈Android开发经验
- 简单新闻客户端APP设计
- 基于Socket的Android聊天室
- Android开发之UI线程和非UI线程
- android用户界面-事件处理
- Android异步消息处理机制(2)源码解析
- Android应用程序的4个组件
- Android(安卓)java面试题收集