Android组件的使用:ProgressBar与SeekBar
最新推荐文章于 2022-08-18 16:55:21 发布
![](https://img-home.csdnimg.cn/images/20240709112858.png)
Android中ProgressBar(进度条)与SeekBar(拖动条)的使用
1、ProgressBar
1.1、一个简单的ProgressBar
1)、新建一个布局文件progressbar_layout.xml,通过style属性改变进度条显示风格。<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ProgressBar android:id="@+id/pb_showpb" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" style="@android:style/Widget.ProgressBar.Horizontal"/> <TextView android:id="@+id/tv_showpbinfo" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
2)、建立Activity类package com.example.highcomponent; import android.app.Activity; import android.os.Bundle; import android.widget.ProgressBar; import android.widget.TextView; public class ProgressBarDemoActivity extends Activity { // 声明组件信息 private ProgressBar pb_showpb = null; private TextView tv_showpbinfo = null; // 用于显示进度条信息 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.progressbar_layout); // 实例化组件 pb_showpb = (ProgressBar) super.findViewById(R.id.pb_showpb); tv_showpbinfo = (TextView) super.findViewById(R.id.tv_showpbinfo); // 设置进度为10 pb_showpb.setProgress(10); } }
3)、因为程序没有动态改变进度条的进度,运行效果只是一个静态的进度条:
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交
评论
![](https://csdnimg.cn/release/blogv2/dist/pc/img/closeBt.png)
![](https://csdnimg.cn/release/blogv2/dist/pc/img/closeBt.png)
![](https://csdnimg.cn/release/blogv2/dist/pc/img/commentArrowLeftWhite.png)
![](https://csdnimg.cn/release/blogv2/dist/pc/img/iconPark.png)
查看更多评论
![](https://csdnimg.cn/release/blogv2/dist/pc/img/commentArrowDownWhite.png)
添加红包
![](https://csdnimg.cn/release/blogv2/dist/pc/img/guideRedReward02.png)
![](https://csdnimg.cn/release/blogv2/dist/pc/img/guideRedReward03.png)