手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android软件启动动画及动画结束后跳转的实现方法
Android软件启动动画及动画结束后跳转的实现方法
摘要:本文实例讲述了Android软件启动动画及动画结束后跳转的实现方法。分享给大家供大家参考,具体如下:自己写了个小程序,软件启动时,先显示几张...

本文实例讲述了Android软件启动动画及动画结束后跳转的实现方法。分享给大家供大家参考,具体如下:

自己写了个小程序,软件启动时,先显示几张图片,每3秒显示一张,图片显示完跳转到首页

1. 图片轮播使用Gallery,用法很简单

GalleryAdapter adapter = new GalleryAdapter(this, mIds); mGallery.setAdapter(adapter);

GalleryAdapter是自定义适配器

public class GalleryAdapter extends BaseAdapter { private Context mContext; private int mImageHeight; private int[] mIds; public GalleryAdapter(Context context, int[] ids) { this.mContext = context; this.mIds = ids; init(); } private void init() { mImageHeight = px2dip(mContext, getScreenHeight(MainActivity.this)); } @Override public int getCount() { return mIds.length; } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { final ImageView imageView = new ImageView(mContext); if (position < mIds.length) { int imageId = mIds[position]; imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);//设置图片居中 imageView.setLayoutParams(new Gallery.LayoutParams( Gallery.LayoutParams.FILL_PARENT, mImageHeight)); Bitmap bitmap = readBitMap(mContext, imageId);//用节省内存的方式加载图片,防止OOM imageView.setImageBitmap(bitmap); overridePendingTransition(R.anim.push_in, R.anim.push_out);//图片切换动画 } return imageView; } }

2. 设置图片切换时间使用Timer定时器

Timer timer = new Timer(); timer.schedule(task, 3000, 3000);// 每3秒切换一张图片 private TimerTask task = new TimerTask() { @Override public void run() { Message message = new Message(); message.what = 0; index = mGallery.getSelectedItemPosition(); handler.sendMessage(message); index++; if (index == mIds.length - 1) { this.cancel(); MainActivity.this.finish(); Intent intent = new Intent(MainActivity.this, Test.class); startActivity(intent); } } }; //不能直接在task中更新UI,所以用handler向主线程发送消息 private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 0: mGallery.setSelection(index); break; default: break; } } };

3. 读取本地资源图片

public static Bitmap readBitMap(Context context, int resId) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inPreferredConfig = Bitmap.Config.RGB_565; opt.inPurgeable = true; opt.inInputShareable = true; // 获取资源图片 InputStream is = context.getResources().openRawResource(resId); return BitmapFactory.decodeStream(is, null, opt); }

完整实例代码代码点击此处本站下载。

希望本文所述对大家Android程序设计有所帮助。

【Android软件启动动画及动画结束后跳转的实现方法】相关文章:

Android 设置应用全屏的两种解决方法

Android中监听系统网络连接打开或者关闭的实现代码

Android开发:自动开关机实现教程

Android读取用户号码,手机串号,SIM卡序列号的实现代码

Android设置桌面背景图片的实现方法

Android上使用jspf插件框架的方法

android apk反编译到java源码的实现方法

Android获取本机电话号码的简单方法

android屏幕全屏的实现代码

Android 完全退出应用程序的解决方法

精品推荐
分类导航