标签:
ProgressBar是一个进度条(文件的下载,大量数据的处理时要显示的进度)
代码示例:
ProgressBar.java中的代码:
public class ProgressBarTest extends Activity { //声明变量 private ProgressBar firstBar; private ProgressBar secondBar; private Button bt; private int i=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity); final ProgressBar firstBar=(ProgressBar)findViewById(R.id.firstBar); final ProgressBar secondBar=(ProgressBar)findViewById(R.id.secondBar); Button bt=(Button)findViewById(R.id.button1); bt.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { if(i == 0){ //设置进度条可见 firstBar.setVisibility(View.VISIBLE); secondBar.setVisibility(View.VISIBLE); }else if(i<firstBar.getMax()){ firstBar.setProgress(i); secondBar.setProgress(i+10); }else{ //设置进度条不可见 firstBar.setVisibility(View.GONE); secondBar.setVisibility(View.GONE); } i=i+10; } }); } }
activity.xml中的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="14dp" android:text="test_view" /> <ProgressBar android:id="@+id/firstBar" //进度条的样式,圆圈样式 style="?android:attr/progressBarStyleLarge" android:layout_width="120dp" android:layout_height="wrap_content" android:visibility="gone"/> <ProgressBar android:id="@+id/secondBar" //水平方式的进度条 style="?android:attr/progressBarStyleHorizontal" android:layout_width="300dp" //高度包含内容 android:layout_height="wrap_content" android:max="100"/> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="begin" /> </LinearLayout>
标签:
原文地址:http://blog.csdn.net/lilu920923/article/details/46044171