目录
ProgressBar(进度条)
ProgressBar是Android下的进度条,也是为数不多的直接继承于View类的控件.
ProgressBar属性
ProgressBar样式设定有两种方式.
第一种:
属性 |
---|
Widget.ProgressBar.Horizontal |
Widget.ProgressBar.Small |
Widget.ProgressBar.Large |
Widget.ProgressBar.Inverse |
Widget.ProgressBar.Small.Inverse |
Widget.ProgressBar.Large.Inverse |
第二种:
属性 |
---|
style="?android:attr/progressBarStyle" |
style="?android:attr/progressBarStyleHorizontal" |
style="?android:attr/progressBarStyleInverse" |
style="?android:attr/progressBarStyleLarge" |
style="?android:attr/progressBarStyleLargeInverse" |
style="?android:attr/progressBarStyleSmall" |
style="?android:attr/progressBarStyleSmallInverse" |
style="?android:attr/progressBarStyleSmallTitle" |
另外
ProgressBar有两个进度,一个是android:progress,另一个是android:secondaryProgress。后者主要是为缓存需要所涉及的,比如在看网络视频时候都会有一个缓存的进度条以及还要一个播放的进度,在这里缓存的进度就可以是android:secondaryProgress,而播放进度就是android:progress。
使用实例
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<ProgressBar
android:id="@+id/bar1"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="155dp"
android:layout_marginLeft="155dp"
android:layout_marginTop="220dp"
android:layout_marginEnd="181dp"
android:layout_marginRight="181dp"
android:layout_marginBottom="243dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="@+id/bar3"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.808"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.498" />
<ProgressBar
android:id="@+id/bar4"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.206"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.478" />
<ProgressBar
android:id="@+id/bar2"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="63dp"
android:layout_marginEnd="336dp"
android:layout_marginRight="336dp"
android:layout_marginBottom="413dp"
android:max="100"
android:progress="50"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text"
app:layout_constraintVertical_bias="1.0" />
<ProgressBar
android:id="@+id/bar5"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="257dp"
android:layout_marginEnd="336dp"
android:layout_marginRight="336dp"
android:layout_marginBottom="59dp"
android:max="100"
android:progress="50"
android:progressDrawable="@android:drawable/progress_indeterminate_horizontal"
app:layout_constraintBottom_toTopOf="@+id/bar6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bar2" />
<ProgressBar
android:id="@+id/bar6"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="59dp"
android:layout_marginEnd="336dp"
android:layout_marginRight="336dp"
android:layout_marginBottom="65dp"
android:max="100"
android:progress="50"
android:progressDrawable="@drawable/ic_launcher_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bar5" />
</android.support.constraint.ConstraintLayout>
网友评论