发布于 2016-05-20 10:45:19 | 383 次阅读 | 评论: 0 | 来源: 网友投递
Android移动端操作系统
Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。
这篇文章主要介绍了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);
}