首先先写布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_scanner_malware">
<ImageView
android:id="@+id/img_scale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/act_scanning_03"/>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"/>
<ProgressBar
android:id="@+id/pb_main"
android:progressDrawable="@drawable/my_progressbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"/>
</LinearLayout>
</LinearLayout>
初始化id后,对图片进行旋转动画
private void setRoteAnimation() {
RotateAnimation toAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
toAnimation.setDuration(1000);
toAnimation.setRepeatCount(Animation.INFINITE);
toAnimation.setInterpolator(new LinearInterpolator());
img_scale.startAnimation(toAnimation);
}
旋转动画后,进行模拟扫描,启用异步任务做
private void scale() {
new AsyncTask<Void, Void, Void>() {
//主线程,显示提示视图
protected void onPreExecute() {
tv_title.setText("手机杀毒引擎正在扫描中...");
};
//分线程,做长时间的工作(扫描)
@Override
protected Void doInBackground(Void... params) {
int appCount = 60;
pb_main.setMax(appCount);
for (int i = 0; i < appCount; i++) {
SystemClock.sleep(40);
//扫描完成一个,发布进度
publishProgress();
}
return null;
}
//在主线程中执行更新进度
protected void onProgressUpdate(Void[] values) {
pb_main.incrementProgressBy(1);
};
//主线程,更新界面
protected void onPostExecute(Void result) {
pb_main.setVisibility(View.GONE);
tv_title.setText("扫描完成");
img_scale.clearAnimation();
};
}.execute();
}
都写完后,只剩最后一步,对水平进度条进行修改,使用自定义的进度条
(就是上篇文章中的自定义进度条中的自定义水平进度条的内容)