ProgressBar的使用
2016-02-03 13:42
309 查看
圆形:style="?android:attr/progressBarStyleLarge"
效果:
条形:style="?android:attr/progressBarStyleHorizontal"
效果:
xml
java代码
package com.example.assembly;
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;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView showTv;
private String str = "";
private ProgressBar pb1, pb2;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showTv = (TextView) findViewById(R.id.show);
pb1 = (ProgressBar) findViewById(R.id.pb1);
pb2 = (ProgressBar) findViewById(R.id.pb2);
showTv.setText(pb2.getProgress() + "");
btn=(Button) findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
pb2.setProgress(pb2.getProgress() + 10);
showTv.setText(pb2.getProgress() + "");
}
});
}
}
总效果图:
效果:
条形:style="?android:attr/progressBarStyleHorizontal"
效果:
xml
<?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:gravity="center_horizontal" android:orientation="vertical" > <ProgressBar android:id="@+id/pb1" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:max="100" android:progress="30" /> <ProgressBar android:id="@+id/pb2" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" android:progress="30" /> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="增加条形进度条"/> <TextView android:id="@+id/show" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
java代码
package com.example.assembly;
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;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView showTv;
private String str = "";
private ProgressBar pb1, pb2;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showTv = (TextView) findViewById(R.id.show);
pb1 = (ProgressBar) findViewById(R.id.pb1);
pb2 = (ProgressBar) findViewById(R.id.pb2);
showTv.setText(pb2.getProgress() + "");
btn=(Button) findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
pb2.setProgress(pb2.getProgress() + 10);
showTv.setText(pb2.getProgress() + "");
}
});
}
}
总效果图:
相关文章推荐
- android确定取消对话框以及单选多选对话框
- vmware虚拟机安装CENTOS系统使用NAT连接网络方法
- addEventListener() 方法
- Leetcode题解(30)
- 一个后端的前端学习之旅——1.决定学什么
- Appium1.4 的简介、装配及其使用真机测试(IOS版)
- OSChina中远程GIT仓库同步探索
- jQuery原理系列-工具函数
- addEventListener() 方法
- 新浪微博UWP UI意见征求
- 六. Redis发布订阅机制
- iOS入门学习(Objective-c类的声明与实现)
- 无敌子网掩码(IP地址)计算方法(完全心算法)
- RAC中数据文件创建到了本地路径(非系统表空间) 使用rman转移
- 六. Redis发布订阅机制
- java可变参数Varargs
- 收藏一些常用的linux命令,用处很大。
- LIS 两种复杂度解法
- HYSBZ/BZOJ 1008 [HNOI2008] 越狱 - 组合数学
- 进程和线程的使用