android 中ProgressBar的使用

仓廪实则知礼节,衣食足则知荣辱。这篇文章主要讲述android 中ProgressBar的使用相关的知识,希望能为你提供帮助。
教程适合初级:
 

1.主线程接收下载完成的消息
private Handler mhandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
mprogressBar.setMax(100); //设置最大
mprogressBar.setProgress(counter); //进度值
return false;
}
});
2.LayoutInflater.from布局管理器

/*

从一个Context中,获得一个布局填充器,这样你就可以使用这个填充器来把xml布局文件转为View对象了。
//加载布局管理器
LayoutInflater inflater = LayoutInflater.from(context);
//将xml布局转换为view对象
convertView = inflater.inflate(R.layout.item_myseallist,parent, false);
//利用view对象,找到布局中的组件
convertView.findViewById(R.id.delete);
*/
mprogressBar = (ProgressBar) LayoutInflater.from(this).inflate(R.layout.process,null);
3.view设置.
setProgressBar

mStreetView.setProgressBar(mprogressBar);
4.子线程下载,发送消息

//子线程
private void startProcess() {

new Thread(){
public static final int MSG = 1;
@Override
public void run() {

if (counter< max){
counter += 10; //一次增加10

Message msg = new Message();
msg.what = MSG;
mhandler.sendMessage(msg);
}
}
};
}
5.将进度条设置颜色等。

以下为全部代码:

public class StreetView extends Activity implements View.OnClickListener{
private com.leador.streetview.truevision.StreetView mStreetView,mStreetView1;
private TextView tv_title;
private LinearLayout ll_back;
private ProgressBar mprogressBar;
int counter=0;

private Handler mhandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
mprogressBar.setMax(100); //设置最大
mprogressBar.setProgress(counter); //进度值
return false;
}
});


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_street_view);

/*
/从一个Context中,获得一个布局填充器,这样你就可以使用这个填充器来把xml布局文件转为View对象了。

//加载布局管理器
LayoutInflater inflater = LayoutInflater.from(context);
//将xml布局转换为view对象
convertView = inflater.inflate(R.layout.item_myseallist,parent, false);
//利用view对象,找到布局中的组件
convertView.findViewById(R.id.delete);
*/
mprogressBar = (ProgressBar) LayoutInflater.from(this).inflate(R.layout.process,null);

tv_title = (TextView) findViewById(R.id.tv_top);
ll_back = (LinearLayout) findViewById(R.id.ll_back);
mStreetView = (com.leador.streetview.truevision.StreetView) findViewById(R.id.gl);
mStreetView1 = (com.leador.streetview.truevision.StreetView) findViewById(R.id.gl1);

init();
loadStreetView();
startProcess();
}

private voidinit(){
tv_title.setText("woququququuq");

mStreetView.setProgressBar(mprogressBar);
mStreetView1.setProgressBar(mprogressBar);

ll_back.setOnClickListener(this);
}

//子线程
private void startProcess() {

new Thread(){
public static final int MSG = 1;
@Override
public void run() {

if (counter< max){
counter += 10; //一次增加10

Message msg = new Message();
msg.what = MSG;
mhandler.sendMessage(msg);
}
}
};
}

private void loadStreetView(){
mStreetView.setStreetViewFirstLoadListener(new StreetViewFirstLoadListener() {
@Override
public void firstLoad() {
mStreetView.loadStreetViewByPosition(110.4010705,19.977281293);
}
});

mStreetView1.setStreetViewFirstLoadListener(new StreetViewFirstLoadListener() {
@Override
public void firstLoad() {
mStreetView1.loadStreetViewByPosition(110.4010705,19.977281293);
}
});
}

@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.ll_back:
finish();
break;
}
}

@Override
protected void onDestroy() {
super.onDestroy();
mStreetView.finish();
}
}

【android 中ProgressBar的使用】android 中ProgressBar的使用
-------------------------------------------------------------------------------------------------------------------------------------
--
vv
--

































































































































































    推荐阅读