本文主要是介绍android中的ProgressBar的使用方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先还是ProgressBarTest.java主activity的内容:
package txlong.ProgressBar;import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;public class ProgressBarTest extends Activity {private ProgressBar psb1, psb2;private Button btn;private int flag;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);psb1 = (ProgressBar) findViewById(R.id.psb1);psb2 = (ProgressBar) findViewById(R.id.psb2);btn = (Button) findViewById(R.id.btn);psb1.setMax(100);btn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if (flag == 0) {psb1.setProgress(0);psb1.setSecondaryProgress(0);psb1.setVisibility(View.VISIBLE);psb2.setVisibility(View.VISIBLE);} else if (flag < psb1.getMax()) {psb1.setProgress(flag);psb1.setSecondaryProgress(flag + 10);} else {psb1.setVisibility(View.GONE);psb2.setVisibility(View.GONE);flag = -10;}flag += 10;}});}
}
然后是main.xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello"/><ProgressBarandroid:id="@+id/psb1"style="?android:attr/progressBarStyleHorizontal"android:layout_width="fill_parent"android:layout_height="wrap_content"android:visibility="gone"/><ProgressBarandroid:id="@+id/psb2"style="?android:attr/progressBarStyle"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="gone"/><Buttonandroid:id="@+id/btn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="click"/></LinearLayout>
这篇关于android中的ProgressBar的使用方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!