美文网首页Android UIAndroid技术知识Android开发
Android知识点——indeterminate属性

Android知识点——indeterminate属性

作者: 小编 | 来源:发表于2017-02-28 13:38 被阅读178次

属性:android:indeterminate

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

如下图(忽略因录制导致的卡顿问题)
实际情况还是蛮顺畅的


  • 实现如上效果,设置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

<?xml version="1.0" encoding="utf-8"?>
<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

<SeekBar
        android:layout_width="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"/>

<ProgressBar
    android:layout_width="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属性

本文链接:https://www.haomeiwen.com/subject/euexgttx.html