关注 安卓007 ,免费获取全套安卓开发学习资料
什么是ProgressBarProgressBar是用于提示用户进行等待的UI控件,.
基础样例 1.loading图 效果图- 布局文件代码
- activity代码
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//隐藏进度条
progressBar.visibility = View.GONE
//显示进度条
progressBar.visibility = View.VISIBLE
}
}
2.横向进度条
效果图
- 布局文件代码
- activity代码
//横向进度条:设置进度
horizontalProgressBar.progress = 50
3.横向loading图
效果图
基础样例完整源代码
https://gitee.com/cxyzy1/ProgressBarDemo
常用属性说明 属性名用途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-100style设置显示样式."?android:attr/progressBarStyle":转圈loading图;"?android:attr/progressBarStyleHorizontal":横向进度条;"?android:attr/progressBarStyleHorizontal":横向loading图; 更多属性及实际效果,可以在开发工具里自行体验. 安卓开发入门教程系列汇总 开发语言学习Kotlin语言基础
UI控件学习系列UI控件_TextView UI控件_EditText UI控件_Button UI控件_ImageView UI控件_RadioButton UI控件_CheckBox UI控件_ProgressBar
关注头条号,第一时间获取最新文章: