[Android开发视频教学].01_13_Android常见控件(三)之一
学习使用ProgressBar
<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="@string/hello_world"
tools:context=".Activity08" />
<ProgressBar
android:id="@+id/progressBar1"
style="@android:style/Widget.ProgressBar.Small"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<ProgressBar
android:id="@+id/progressBar2"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button" />
</LinearLayout>
注:关于ProgressBar的样式,在视频教程中看到是这样的
style="?android:attr/progressBarStyleHorizontal"
但是这个格式在Eclipse中没有提示,看了下帮助文档,也可以这样写的
style="@android:style/Widget.ProgressBar.Horizontal"
package fengda.android08;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
public class Activity08 extends Activity {
private ProgressBar progressBar1;
private ProgressBar progressBar2;
private Button button;
private int i =0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity08);
progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);
progressBar2 = (ProgressBar) findViewById(R.id.progressBar2);
button = (Button) findViewById(R.id.button);;
button.setOnClickListener( new ButtonOnClickListener());
}
class ButtonOnClickListener implements OnClickListener {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (i==0){
progressBar1.setVisibility(View.VISIBLE);
progressBar2.setVisibility(View.VISIBLE);
} else if(i<100){
progressBar1.setProgress(i);
progressBar2.setProgress(i);
progressBar2.setSecondaryProgress(i+10);
} else {
progressBar1.setVisibility(View.GONE);
progressBar2.setVisibility(View.GONE);
}
i = i+10;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_activity08, menu);
return true;
}
}