Android知识点——indeterminate属性

属性:android:indeterminate

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

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

《Android知识点——indeterminate属性》

  • 实现如上效果,设置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.jianshu.com/p/6aefe8b26adc
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞