首页 > 代码库 > 雷达扫描
雷达扫描
转载请注明出入:http://blog.csdn.net/forwardyzk/article/details/42640031
模拟扫描文件的效果,模拟雷达扫描。
思路:
1.使用旋转动画和渐变动画的结合。
2.使用线程和Handler进行消息的传递,刷新界面
不要在主线程上做耗时操作,不要在主线程上刷新界面。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="120dip" android:orientation="horizontal" > <FrameLayout android:layout_width="120dip" android:layout_height="120dip" > <ImageView android:layout_width="80dip" android:layout_height="80dip" android:layout_gravity="center" android:src=http://www.mamicode.com/"@drawable/act_radar_bg" />>MainActivity.java初始化动画
animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setDuration(2000); animation.setRepeatCount(Animation.INFINITE); animation2 = new AlphaAnimation(0.0f, 1.0f); animation2.setDuration(3000); animation2.setRepeatCount(Animation.INFINITE); im_scan.startAnimation(animation); im_dian.startAnimation(animation2);
开启线程thread = new Thread() { public void run() { pb_loding.setMax(200); for (count = 1; count <= pb_loding.getMax(); count++) { Message msg = Message.obtain(); msg.what = SCAN_LODING; handler.sendMessage(msg); pb_loding.setProgress(count); SystemClock.sleep(200); } Message msg = Message.obtain(); msg.what = FINSH_SCAN; handler.sendMessage(msg); }; }; thread.start();
刷新界面private Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case SCAN_LODING: TextView tv = new TextView(MainActivity.this); tv.setTextSize(14); tv_count.setText("已扫描:" + count + "个文件"); tv_lodingApk.setText("正在扫描:第" + count + "个文件"); if (count - 1 != 0) tv.setText("第" + (count - 1) + "个文件已经扫描"); ll_scanText.addView(tv, 0); break; case FINSH_SCAN: tv_lodingApk.setText("扫描完毕"); TextView tv1 = new TextView(MainActivity.this); tv1.setTextSize(14); tv1.setText("第" + count + "个文件已经扫描"); ll_scanText.addView(tv1, 0); im_scan.clearAnimation();// 清除此ImageView身上的动画 im_dian.clearAnimation();// 清除此ImageView身上的动画 break; } }; };
源码下载: http://download.csdn.net/detail/forwardyzk/8352683效果图:
雷达扫描
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。