ProgressBar进度条控件
2015-11-10 17:28
253 查看
PregressBar可以用来设置进度,可以设置为圆圈形或者条形,案例图如下
activity代码
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <!-- 设置控件样式 --> <ProgressBar style="?android:attr/progressBarStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ProgressBar style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ProgressBar style="?android:attr/progressBarStyleHorizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:progress="30" /> <ProgressBar android:id="@+id/progress" style="?android:attr/progressBarStyleHorizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:secondaryProgress="60" android:layout_marginTop="40dip" android:progress="30" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/btn_add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="增加" /> <Button android:id="@+id/btn_cutback" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="减少" /> </LinearLayout> </LinearLayout>
activity代码
package progress.bar; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ProgressBar; public class ProgressBarActivity extends Activity implements OnClickListener { private Button btn_add; private Button btn_cutback; private ProgressBar progress; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn_add=(Button)findViewById(R.id.btn_add); btn_cutback=(Button)findViewById(R.id.btn_cutback); progress=(ProgressBar)findViewById(R.id.progress); btn_add.setOnClickListener(this); btn_cutback.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.btn_add: //拿到当前进度 int currentProgress= progress.getProgress(); int prog = (int)( currentProgress*1.2); progress.setProgress(prog); break; case R.id.btn_cutback: //拿到当前进度 int currentProgress2= progress.getProgress(); int prog2 = (int)( currentProgress2*0.8); progress.setProgress(prog2); } } }
相关文章推荐
- Dapper的使用
- Android Fragment 真正的完全解析(上)
- Android——实用小技巧
- callback.js
- HLSL编译工具—FXC
- Apache下htaccess有关301重定向、404错误的设置
- Outlook客户端无法发送附件,频繁与Exchange服务器断开现象解决方案
- 所有重复都适用的去重方法
- 如何启动公司内部的devops运动--尤其是后端开发人员&运维
- c++程序的内存格局
- python 模块学习
- array.js
- asynchronous.js
- OCX RegSvr32 error
- 存储类的仓库之Java常用类库(一)
- po主去研究root了
- [LeetCode] Product of Array Except Self
- 使用zookeeper管理多个hbase集群
- 读写Xml文件
- nyoj 821