<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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="简单进度条的展示"
android:layout_gravity="center_horizontal"/>
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<ProgressBar
android:id="@+id/progressBar3"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:max="100"
android:minWidth="180dip"
android:minHeight="40dip"
/>
</LinearLayout>
package com.kiritor.ui_progressbar;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ProgressBar;
public class MainActivity extends Activity implements Runnable {
private ProgressBar bar = null;
private Thread thread = null;// 声明一个线程
private boolean stateChange;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bar = (ProgressBar) findViewById(R.id.progressBar3);
thread = new Thread(this);
thread.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void run() {
while (true) {
int current = bar.getProgress();// 得到当前进度值
int currentMax = bar.getMax();// 得到进度条的最大进度值
//int secCurrent = bar.getSecondaryProgress();// 得到底层当前进度值
// 以下代码实现进度值越来越大,越来越小的一个动态效果
if (stateChange == false) {
if (current >= currentMax) {
stateChange = true;
} else {
// 设置进度值
bar.setProgress(current + 1);
// 设置底层进度值
bar.setSecondaryProgress(current + 1);
}
} else {
if (current <= 0) {
stateChange = false;
} else {
bar.setProgress(current - 1);
bar.setSecondaryProgress(current - 1);
}
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有