布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!--
進度條
progressbar
默认是圆圈,不知道加载时间是多长的时候使用。一直转
-->
<ProgressBar
android:id="@+id/pg1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ProgressBar
android:id="@+id/pg2"
style="@android:style/Widget.DeviceDefault.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="20" />
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:max="100" />
<RatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/bt"
android:onClick="aaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DialogProgress" />
</LinearLayout>
mainActivity
package wzq.com.aa;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends Activity {
private int progress = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ProgressBar pg1 = (ProgressBar) findViewById(R.id.pg1);
final ProgressBar pg2 = (ProgressBar) findViewById(R.id.pg2);
final SeekBar sb1 = (SeekBar) findViewById(R.id.seekBar);
sb1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
Log.e("进度改变" , progress+"");
}
});
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
progress += 10;
sb1.setProgress(progress);
pg2.setProgress(progress);
if (progress >= 100) {
timer.cancel();
}
}
}, 0, 1000);
}
public void aaa(View v) {
ProgressDialog dialog = new ProgressDialog(MainActivity.this);
dialog.setTitle("进度条");
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setProgress(20);
dialog.show();
}
}