您的位置:首页 > 其它

ProgressBar的使用

2016-02-03 13:42 309 查看
圆形:style="?android:attr/progressBarStyleLarge"
效果:



条形: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() + "");
}
});
}
}


总效果图:


      
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: