什麼是SeekBar
SeekBar是支持拖動的進度顯示條.
基礎樣例
1. 普通樣例
效果圖
代碼
- 佈局文件
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="50" />
- activity代碼
//設置進度
seekBar.progress = 60
2. 分段可拖動進度條樣例
效果圖
代碼
- 佈局文件
<SeekBar
android:id="@+id/discreteSeekBar"
style="@style/Widget.AppCompat.SeekBar.Discrete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="10"
android:progress="3" />
基礎樣例完整源代碼
https://gitee.com/cxyzy1/SeekBarDemo
常用屬性說明
屬性名 | 用途 |
---|---|
android:layout_width | 設置控件寬度,可設置爲:match_parent(和父控件一樣),wrap_content(按照內容自動伸縮),設置固定值(如200dp) |
android:layout_height | 設置控件高度,可設置爲:match_parent(和父控件一樣),wrap_content(按照內容自動伸縮),設置固定值(如200dp) |
android:gravity | 控件內對齊方式 |
android:background | 設置背景,可以是色值(如#FF0000)或圖片等 |
android:visibility | 可選值: visible(顯示), invisible(隱藏,但是仍佔據UI空間),gone(隱藏,且不佔UI空間) |
android:progress | 設置進度(對橫向進度條有用),取值範圍:0-100 |
android:max | 對於分段可拖動進度條,設置分段數 |
更多屬性及實際效果,可以在開發工具裏自行體驗.