android ProgressBar 的使用
16lz
2021-12-04
1. main文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleHorizontal" android:layout_width="255dp" android:layout_height="wrap_content" android:visibility="gone" /> <ProgressBar android:id="@+id/progressBar2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" /> <Button android:id="@+id/button" android:text="Ok" android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>
2. java 文件的写法
package com.android.voew;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;/** * * @author liuqing * @version 1.0 * @see Android ProgreeBar 的使用 * 2011-10-12 * */public class Viewchapter3Activity extends Activity { /** Called when the activity is first created. */private ProgressBar firstProgree;private ProgressBar secondProgree;private Button button;private int i = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.firstProgree = (ProgressBar)this.findViewById(R.id.progressBar1); this.secondProgree = (ProgressBar)this.findViewById(R.id.progressBar2); this.button = (Button)this.findViewById(R.id.button); this.button.setOnClickListener(new ButtonListener()); } //添加OnClickListener方法 class ButtonListener implements OnClickListener {@Overridepublic void onClick(View v) {if (i == 0) {firstProgree.setMax(150);secondProgree.setMax(150);firstProgree.setVisibility(View.VISIBLE);secondProgree.setVisibility(View.VISIBLE);button.setText("Begin");i++;}else {firstProgree.setProgress(i * 10);//设进度条的从进度属性firstProgree.setSecondaryProgress((i * 10) + 10);secondProgree.setProgress(i * 10);if (firstProgree.getMax() <= i * 10) {firstProgree.setVisibility(View.GONE);i = 0;button.setText("OK");secondProgree.setVisibility(View.GONE);}i++;}} }}
更多相关文章
- android getResources的作用
- Android(安卓)文件的保存与读取之SDCard(SD卡)存储
- Android(安卓)DEV : setOnClickListener() vs. android:onClick
- 获取apk信息工具(android SDK的aapt工具)
- 开发可统计单词个数的Android驱动程序(1)
- Android(安卓)Layout布局文件里的android:layout_height等属性为
- Android(安卓)Studio 导入so
- Android(安卓)修改开机动画(bootanimation)
- android中下载文件到sdcard和进度条小结