安卓开发入门教程-UI控件_SeekBar

什么是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对于分段可拖动进度条,设置分段数

更多属性及实际效果,可以在开发工具里自行体验.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值