安卓控件使用系列20:ProgressBar进度条控件的使用方法
来源:互联网 发布:阿里云ecs搭建ss 编辑:程序博客网 时间:2024/05/17 04:20
安卓中的进度条是经常使用的控件之一,下面我们来一起分享一下各种类型的进度条的使用。
这个例子显示的是小中大圆形进度条和水平进度条,通过按下增加进度和减少进度来控制进度条上进度的增加和减少。
整体思路:通过设置ProgressBar的style属性来控制进度条的显示类型,是圆形还是水平,是大还是小,不进行设置的话默认为是中型圆形进度条的显示效果。在活动中设置进度条的初始属性和刻度,点击按钮的OnClick事件中,获取当前的进度进行增加或减少。
activity_main.xml文件:
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="小型圆形进度条" /> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/progressBarStyleSmallTitle" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="中型圆形进度条" /> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="大型圆形进度条" /> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/progressBarStyleLarge" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="水平进度条" /> <ProgressBar android:layout_width="fill_parent" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" android:max="100" android:progress="30" /> <ProgressBar android:id="@+id/progressbar" android:layout_width="fill_parent" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" android:max="100" android:progress="30" android:secondaryProgress="60" android:layout_marginTop="20dp" /></LinearLayout><LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="增加进度" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="减少进度" /></LinearLayout>
MainActivity.java文件:
public class MainActivity extends Activity implements OnClickListener{ private ProgressBar progressBar; private Button button1,button2;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//如何设置窗口有刻度的效果requestWindowFeature(Window.FEATURE_PROGRESS);requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);setContentView(R.layout.activity_main);//这句话必须在上面两句话的下面,否则报错。progressBar=(ProgressBar)findViewById(R.id.progressbar);setProgressBarVisibility(true);setProgressBarIndeterminate(true);setProgress(3500);//设置刻度为3500button1=(Button)findViewById(R.id.button1);button2=(Button)findViewById(R.id.button2);button1.setOnClickListener(this);button2.setOnClickListener(this);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch (v.getId()) {case R.id.button1:progressBar.setProgress((int)(progressBar.getProgress()*1.2));progressBar.setSecondaryProgress((int)(progressBar.getSecondaryProgress()*1.2));break;case R.id.button2:progressBar.setProgress((int)(progressBar.getProgress()*0.8));progressBar.setSecondaryProgress((int)(progressBar.getSecondaryProgress()*0.8));break;}}}
0 0
- 安卓控件使用系列20:ProgressBar进度条控件的使用方法
- 安卓控件使用系列14:ImageView的基本使用方法
- gtk progressbar 进度条控件的使用
- 安卓进度条组件ProgressBar的使用
- 安卓控件使用系列21:RatingBar评分控件的使用方法
- 安卓控件使用系列22:ScrollView垂直滚动控件的使用方法
- 安卓控件使用系列23:HorizontalScrollView 水平滚动控件的使用方法
- 安卓控件使用系列24:Gallery画廊控件的使用方法
- 安卓控件使用系列25:Spinner下拉列表控件的使用方法
- 安卓控件使用系列26:ImageSwitcher图片切换控件的使用方法
- 安卓控件使用系列27:GridView网格控件的使用方法
- 安卓控件使用系列31:ViewStub惰性装载控件的使用方法
- 安卓控件使用系列32:ViewPager多页面滑动控件的使用方法1
- 安卓控件使用系列33:ViewPager多页面滑动控件的使用方法2
- 安卓控件使用系列34:ListView列表控件显示表单的使用方法1
- 安卓控件使用系列35:ListView列表控件显示表单的使用方法2
- 【Android 开发】:UI控件之 ProgressBar 进度条的使用
- C# 多线程使用progressBar进度条控件
- const成员函数、inline成员函数、static成员函数中关键字的位置
- postMessage安全性问题
- java篇 【14】Java 继承
- 关于应急道占用问题
- 【Cpp】删除字符串空格
- 安卓控件使用系列20:ProgressBar进度条控件的使用方法
- 弱校联萌十一大决战之强力热身 C题
- Ext.grid.plugin.RowExpander的简单用法
- Spark On YARN内存分配
- <线段树>寻找神格
- 黑马程序员——Java开发前奏
- [经济学原理|政治部分]剩余价值理论
- nyoj 71 独木舟上的旅行
- HDOJ 5480 Conturbatio