进度条小应用
来源:互联网 发布:windows上类似imovie 编辑:程序博客网 时间:2024/06/05 05:16
进度条小应用
今天做了一个进度条小应用,给大家分享一下。下面是我做的界面。
首先编写xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:gravity="center"
android:background="#ffcfef"
android:text="手机杀毒" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<FrameLayout
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/ic_scanner_malware">
<ImageView
android:id="@+id/iv_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/act_scanning_03" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_margin="10dp">
<TextView
android:id="@+id/tv_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text" />
<ProgressBar
android:id="@+id/pb_main"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:progressDrawable="@drawable/my_progress"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
编写的时候遇到的一些问题:
1 之前的时候用的是eclipse,把所有的东西都清空后直接能把线性布局给拉过来,但是android studio 不行,得自己写,同时编写第一个的时候不会有提示。但是第二个之后就会有提示。
2 这里的进度条用的不是系统给的,所以在drawable文件中写一个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>
Mainactivity的编写主要分两部分:
1 左边图形的旋转:即用的是旋转动画,详解请看上一篇博客
private void showAnimation() {
RotateAnimation rotateAnimation = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
rotateAnimation.setDuration(1000);
rotateAnimation.setRepeatCount(Animation.INFINITE);
rotateAnimation.setInterpolator(new LinearInterpolator());
iv_main.startAnimation(rotateAnimation);
}
2 右边进度条:这时需使用异步任务来做:
1 主线程 显示提示视图 onPreExecute()
2 分线程 做长时间的工作(扫描应用,进度条前进)doInBackground(Integer... voids) onProgressUpdate(Double... values)
3 主视图更新界面 onPostExecute(String aVoid)
具体程序见下:
private void showScan() {
final int appCount = 60;
//异步任务
new AsyncTask<Integer,Double,String>(){
//1 主线程 显示提示视图
@Override
protected void onPreExecute() {
tv_main.setText("正在扫描中。。。");
pb_main.setMax(60);
}
//2 分线程 做长时间的工作(扫描应用)
@Override
protected String doInBackground(Integer... voids) {
for(int i = 0;i<appCount;i++){
SystemClock.sleep(40);
publishProgress(i + 0.0);
}
return "成功";
}
//主线程 更新界面
@Override
protected void onPostExecute(String aVoid) {
pb_main.setVisibility(View.GONE);
tv_main.setText("扫描完成,没有病毒");
iv_main.clearAnimation();
Toast.makeText(MainActivity.this,aVoid,Toast.LENGTH_SHORT).show();
}
@Override
protected void onProgressUpdate(Double... values) {
// pb_main.incrementProgressBy(1);
pb_main.setProgress(values[0].intValue());
}
// Pararms[] params
}.execute();
}
以上。
阅读全文
0 0
- 进度条小应用
- 滑动进度条小插件
- linux----进度条小代码
- 进度条小程序
- Linux中ctags、make以及进度条小程序(\r的应用)
- 进度条应用大杂烩
- android 进度条小例子1
- 进度条小飞机移动动画
- Linux之小程序进度条
- Linux下进度条小程序
- makefile 和 进度条小程序
- 289_自定义小进度条
- unbuntu 下进度条小程序
- Linux实现进度条小程序
- Linux入门:进度条小程序
- 自制css3进度条小动画
- Linux简单小程序---进度条
- Androdi 网页记载进度条应用
- TCP的粘包问题
- c++数据结构快速排序
- Java抽象类的概念和使用
- 数据结构--one
- 基于C语言sscanf()函数的深入理解
- 进度条小应用
- poi读写Excel,兼容2007xlsx
- Android客户端之“微服私访”App的系统学习(七)XRecyclerView快速实现列表界面+自定义Search输入框,软键盘搜索按钮监听+TextView部分样式改变
- linux vpn搭建(PPTP)
- Content Provider Resolver
- android开发之Intent传参
- springboot处理静态资源文件
- bug解决心得
- 归并排序