ProgressBar(进度条)控件的简单应用

    当应用程序在进行一些耗时操作时(如网络下载,图片资源的加载等),应用程序会处于一个“等待”的状态,在这个时候如果不通知用户程序正在运行中,用户可能认为程序“未响应”而关闭程序,这样的用户体验显然非常糟糕。因此我们可以用一个进度条让用户知道当前程序的进度信息,提高用户体验。

    Android提供的进度条控件一般以两种样式显示,一种是环形样式,一种是线性样式,可以通过“style”属性来设置样式。此外进度条有“确定”和“不确定”两种,前者可以精确的表示操作执行的进度;后者只能表示操作正在执行,可以通过“android:indeterminate”属性来设置。“确定”的进度条有两个进度,一个是主进度(可表示操作执行的重进度),一个是第二进度(可用来表示缓存进度,如在线看视频的进度条等)

    XML常用属性:
    android:indeterminate   是否设置为不精确模式

    android:progressDrawable   用来设置外观样式

    android:max    设置最大进度值

    android:progress    设置默认第一进度值

    android:secondaryProgress    设置默认第二进度值

    style="?android:attr/progressBarStyleHorizontal"    设置进度条显示样式为线性

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

    getProgress():返回进度

    getSecondaryProgress():返回次要进度

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

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

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

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

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



    效果预览:

这里写图片描述

    1.布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:progressDrawable="@drawable/progress_bar"
        android:id="@+id/progressBar" />

    <TextView
        android:id="@+id/textView"
        android:text=
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值