欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android软件启动动画及动画结束后跳转的实现方法

程序员文章站 2023-11-26 16:48:10
本文实例讲述了android软件启动动画及动画结束后跳转的实现方法。分享给大家供大家参考,具体如下: 自己写了个小程序,软件启动时,先显示几张图片,每3秒显示一张,图片显...

本文实例讲述了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程序设计有所帮助。