Android知识点——indeterminate属性

来源:互联网 发布:淘宝客能挣钱吗 编辑:程序博客网 时间:2024/06/01 09:08

属性: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"/>

这里写图片描述

0 0