一、Progress:表示进度条,本程序在标题栏和Activaty中分别加入进度条。

二、XML重要属性

    android:progressBarStyle:默认进度条样式

    android:progressBarStyleHorizontal:水平样式

三、重要方法

    getMax():返回这个进度条的范围的上限

    getProgress():返回进度

    getSecondaryProgress():返回次要进度

    incrementProgressBy(int diff):指定增加的进度

    isIndeterminate():指示进度条是否在不确定模式下

    setIndeterminate(boolean indeterminate):设置不确定模式下

    setVisibility(int v):设置该进度条是否可视

四、重要事件

    onSizeChanged(int w, int h, int oldw, int oldh):当进度值改变时引发此事件

效果图:

layout中的xml文件:

        
  1. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:orientation="vertical"
  5. android:background="#00ff00">
  6. <ProgressBar
  7. android:id="@+id/myProgressBar"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. style="?android:attr/progressBarStyleSmall" //设置进度条的模式为圆圈旋转模式
  11. />
  12. <ProgressBar
  13. android:id="@+id/myProgressBar2"
  14. android:layout_width="fill_parent"
  15. android:layout_height="wrap_content"
  16. style="?android:attr/progressBarStyleHorizontal"//设置进度条的模式为水平模式
  17. android:max="100" //设置进度条的最大值
  18. android:progress="20"//设置进度条的当前值
  19. android:secondaryProgress="50"//设置进度条的次进度值
  20. />
  21. </LinearLayout>

Activaty.java文件

        
  1. packagecom.cheng.progressbarproject;
  2. importandroid.os.Bundle;
  3. importandroid.app.Activity;
  4. importandroid.view.Menu;
  5. importandroid.view.Window;
  6. publicclassProgressBarActivityextendsActivity{
  7. @Override
  8. protectedvoidonCreate(BundlesavedInstanceState){
  9. super.onCreate(savedInstanceState);
  10. //在窗口标题栏上加进度条,这条语句必须写在super.setContentView(R.layout.main);之前
  11. requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
  12. super.setContentView(R.layout.main);
  13. //设置标题栏上的进度条是可见的
  14. setProgressBarIndeterminateVisibility(true);
  15. }
  16. @Override
  17. publicbooleanonCreateOptionsMenu(Menumenu){
  18. //Inflatethemenu;thisaddsitemstotheactionbarifitispresent.
  19. getMenuInflater().inflate(R.menu.main,menu);
  20. returntrue;
  21. }
  22. }

更多相关文章

  1. Android带播放进度条的音乐播放器
  2. Android关于LinearLayout的设置问题
  3. Textview基本属性及功能
  4. Android(安卓)UI学习 - Tab的学习和使用
  5. android:windowSoftInputMode属性的使用
  6. Android(安卓)虚拟摇杆,多种模式回调,返回距离级别,方向,角度。
  7. android开发之权限问题整理
  8. android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
  9. 【转】善用Android预定义样式来为我们的布局设置效果,大大节约代

随机推荐

  1. ReactNative项目从0.28升级到0.29(Android
  2. android调用手机摄像头拍照
  3. android wifi之WifiMonitor
  4. 自定义ThreadPoolExecutor
  5. Android(安卓)高德地图,显示地图,并定位当
  6. android NDK 入门之在JNI中修改java中对
  7. Android(安卓)NDK: Host 'awk' tool is o
  8. Android实现省市区三级联动
  9. 【Android】【Fragment】Fragment生命周
  10. Android(安卓)- 用WebView开发简单的浏览