本博文源于安卓基础对ProgressBar的测试。进度条(ProgressBar)能以形象的图示直观地显示某个过程的进度。进度的常用属性
属性 | 方法 | 功能 |
---|---|---|
android:max | setMax(int max) | 设置进度条的变化范围为0~max |
android:progress | setProgress(int progress) | 设置进度条的当前值(初始值) |
测试案例效果
具体程序步骤
创建新项目
点进Project—>Empty Activity—>然后finish即可。成功之后,点击箭头运行程序。
程序效果应该可以运行出hello world效果
搭建布局文件
后面对代码有讲解
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"
android:id="@+id/progressBarLarge"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:id="@+id/progressBarNormal"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleSmall"
android:id="@+id/progressBarSmall"
android:layout_marginTop="20dp"
/>
<ProgressBar
android:layout_width="286dp"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/progressBarHorizontal"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:max="100"
android:progress="50"
android:secondaryProgress="80"
/>
</LinearLayout>
LineLayout讲解
这是一个根元素为线性布局的测试,除了设置基本的width与height之外,另外设置orientation方向为垂直,这样就可以有图片效果
ProgressBar讲解
除了设置基本的width与height之外,就是设置了style,style就是progressBar
风格。例如Large就是大,small就是小,normal就是标准。默认normal,其中最后一个为水平,id就是标识控件的。其中max指最大进度值,progress指第一进度值,比如未来的媒体播放进度。secondprogress指第二进度值,比如媒体播放的缓冲进度,我们分别设置了50与80.
最后点击运行
运行就是展现最终效果,虽然安卓很卡,但是安卓一些还是非常有趣的。
总结
- 创建新项目,跑出hello world
- 修改布局文件
- 运行代码
希望此博文对大家有所帮助!