Android知识点——indeterminate属性

属性:android:indeterminate

在对进度条SeekBar或者ProgressBar设置进度的时候,有些时候我们并不知具体进度值是多少,但是也需要有动态进度的提醒。

如下图(忽略因录制导致的卡顿问题)
Android知识点——indeterminate属性_第1张图片

  • 实现如上效果,设置indeterminate 属性为true即可,那么进度条将采用“模糊模式”
<SeekBar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:indeterminate="true"/>

<ProgressBar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/Widget.AppCompat.ProgressBar.Horizontal"
    android:indeterminate="true"/>
  • 设置indeterminate 属性为false,则进度条采用“非模糊模式”。则可以根据实际需求修改进度。

修改样式

在drawable文件夹下定义bar_style.xml


<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape>
            <solid android:color="#ff51495e" />
        shape>
    item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <solid android:color="#ff78495e" />
            shape>
        clip>
    item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <solid android:color="#ff996dfe" />
            shape>
        clip>
    item>
layer-list> 

控件引入drawable

"match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:progressDrawable="@drawable/bar_style"
        android:thumb="@null"
        android:progress="30"
        android:secondaryProgress="40"
        android:indeterminate="false"/>

"match_parent"
    android:progress="30"
    android:layout_height="wrap_content"
    android:secondaryProgress="40"
    android:progressDrawable="@drawable/bar_style"
    style="@style/Widget.AppCompat.ProgressBar.Horizontal"
    android:indeterminate="false"/>

Android知识点——indeterminate属性_第2张图片

你可能感兴趣的:(Android)