杀毒扫描效果【Animation】

功能1 : 雷达扫描旋转动画

功能2 : 自定义水平进度条

代码实现:

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="vertical">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFCFCE"
        android:textSize="25sp"
        android:gravity="center"
        android:text="手机杀毒" 
        android:padding="5dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@drawable/ic_scanner_malware" >

            <ImageView
                android:id="@+id/iv_main_scan"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/act_scanning_03" />

        </FrameLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" 
            android:gravity="center_vertical"
            android:layout_marginLeft="10dp">

            <TextView
                android:id="@+id/tv_main_scan"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="" />

            <ProgressBar
                android:id="@+id/pb_main_scan"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:progressDrawable="@drawable/my_progress" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

MainActivity.java

package com.example.app_animation2;

import java.util.Scanner;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends Activity {

	private ImageView iv_main_scan;
	private TextView tv_main_scan;
	private ProgressBar pb_main_scan;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		iv_main_scan = (ImageView) findViewById(R.id.iv_main_scan);
		tv_main_scan = (TextView) findViewById(R.id.tv_main_scan);
		pb_main_scan = (ProgressBar) findViewById(R.id.pb_main_scan);

		// 1.显示扫描动画
		showScanAnimation();
		// 2.扫描,并显示扫描进度
		scan();
	}

	/**
	 * 扫描,并显示扫描进度
	 */
	private void scan() {
		//启动异步任务做
		new AsyncTask<Void, Void, Void>() {
			
			//1.主线程,显示提示视图
			protected void onPreExecute() {
				tv_main_scan.setText("手机杀毒引擎正在扫描中...");
			}
			
			//2.分线程,做长时间的工作(扫描应用)
			@Override
			protected Void doInBackground(Void... params) {
				int appCount = 60;
				//设置进度条的最大值
				pb_main_scan.setMax(appCount);
				for(int i = 0;i<appCount; i++){
					SystemClock.sleep(40);
					//扫描完成一个
					//发布进度
					publishProgress();
				}
				return null;
			}
			
			//在主线程执行,更新进度
			protected void onProgressUpdate(Void[] values) {
				pb_main_scan.incrementProgressBy(1);//增加1
				//pb_main_scan.setProgress(pb_main_scan.getProgress()+1);
			};	
			
			//3.主线程,更新界面
			protected void onPostExecute(Void result) {
				//隐藏进度条
				pb_main_scan.setVisibility(View.GONE);
				//更新文本
				tv_main_scan.setText("扫描完成,未发现病毒应用,请放心使用!");
				//停止扫描动画
				iv_main_scan.clearAnimation();
			}
		}.execute();
	}

	/**
	 * 显示扫描动画 iv_main_scan的旋转动画
	 */
	private void showScanAnimation() {
		//创建动画对象
		RotateAnimation animation = new RotateAnimation(0, 360,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		//设置
		animation.setDuration(1000);
		animation.setRepeatCount(Animation.INFINITE);
		animation.setInterpolator(new LinearInterpolator());
		//启动
		iv_main_scan.startAnimation(animation);
	}
}
my_progress.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 背景图片 -->
    <item
        android:id="@android:id/background"
        android:drawable="@drawable/security_progress_bg">
    </item>
    <!-- 进度图片 -->
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/security_progress">
    </item>

</layer-list>





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值