Android(java)学习笔记130:ProgressBar使用的
2015-07-27 09:53
615 查看
首先我们看例程如下:
1.main.xml文件如下:
(2)接下来是MainActivity.java文件:
总结:
1:Android的ProgressBar样式:
1.main.xml文件如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="默认进度条:" /> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="progress1" //没有设置style,默认样式,中度旋转的圆形进度条 /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="小圆形进度条:" /> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="progress3" style="?android:attr/progressBarStyleSmall" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="大圆形进度条:" android:layout_gravity="center_vertical" /> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="progress3" style="?android:attr/progressBarStyleLarge" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="条形进度条:" android:id="@+id/tv" /> <ProgressBar android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="progress2" android:id="@+id/porb" style="?android:attr/progressBarStyleHorizontal" android:max="100" android:progress="50" android:secondaryProgress="70" /> </LinearLayout>
(2)接下来是MainActivity.java文件:
package com.progressbar; import android.app.Activity; import android.os.Bundle; import android.widget.ProgressBar; //使用Runnable接口 public class MainActivity extends Activity implements Runnable { private Thread th ; //声明一条线程 private ProgressBar pb ; //声明一个进度条对象 private boolean stateChage; //标识进度值最大最小的状态 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //实例进度条对象 pb = (ProgressBar)findViewById(R.id.porb); th = new Thread(this);//实例线程对象,当前MainActivity实现了Runnable接口,这样MainActivity本身可以作为参数实例化Thread()对象 th.start();//启动线程 } @Override public void run() {//实现Runnable接口抽象函数 while(true){ int current = pb.getProgress();//得到当前进度值 int currentMax = pb.getMax();//得到进度条的最大进度值 int secCurrent = pb.getSecondaryProgress();//得到底层当前进度值 //以下代码实现进度值越来越大,越来越小的一个动态效果 if(stateChage==false){ if(current>=currentMax){ stateChage=true; }else{ //设置进度值 pb.setProgress(current+1); //设置底层进度值 pb.setSecondaryProgress(current+1); } }else{ if(current<=0){ stateChage=false; }else{ pb.setProgress(current-1); pb.setSecondaryProgress(current-1); } } // 设置长方形进度条进度变大和变小的速率快慢 try { Thread.sleep(50); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
总结:
1:Android的ProgressBar样式:
style="?android:attr/progressBarStyleHorizontal" 长形进度条 style="?android:attr/progressBarStyleLarge" 超大号圆形ProgressBar
style="?android:attr/progressBarStyleLargeInverse" 超大号圆形ProgressBar,Inverse反向转向的
style="?android:attr/progressBarStyleSmall" 小号圆形ProgressBar style="?android:attr/progressBarStyleSmallTitle" 标题型圆形ProgressBar 等等还有很多 2.setProgress和setSecondaryProgress区别:这么说你肯定明白:网络视频加载的时候有个播放进度和缓冲进度,播放进度一般可以用setProgerss来显示,而setSecondaryProgress就是用来显示缓冲进度的,同样的360的雷神引擎也是一样,setProgress是文件写入本地进度,setSecondaryProgress就是文件加载进度。还不明就自己写一个Demo测试一遍。写一个把复制文件的程序,setProgress表示往流里面读数据,setSecondaryProgerss表示从流里面输出数据。
相关文章推荐
- Android开发之文件命名规范
- Android性能优化:谈话Bitmap内存管理和优化
- Android——开发框架的使用说明
- android 自定义dialog并实现失去焦点(背景透明)的功能
- ArcGIS Runtime for Android开发教程V2.0(9)基础篇-----查询检索
- ArcGIS Runtime for Android开发教程V2.0(7)基础篇---空间要素可视化2
- ArcGIS Runtime for Android开发教程V2.0(8)基础篇-----地图事件
- Android命令行测试BT WiFi Sensor工作状态
- ArcGIS Runtime for Android开发教程V2.0(6)基础篇---空间要素可视化
- ArcGIS Runtime for Android开发教程V2.0(5)基础篇---图层
- ArcGIS Runtime for Android开发教程V2.0(4)基础篇---MapView
- AndroidJNI.SetCharField 设置字符域
- Android恶意代码分析与渗透测试
- android 读取 AndroidManifest.xml 中的数据:版本号、应用名称、自定义K-V数据(meta-data)
- android_数据库操作_LitePal框架
- android 初识Fresco
- 平安科技移动开发二队技术周报(第十二期)
- Android材料设计兼容函数库(Design Support Library)(II)浮动操作按钮(Floating Action Button)
- Android材料设计兼容函数库(Design Support Library)(I)导航视图(Navigation View)
- Android开发书籍推荐