Progress(进度条):打开文件等的进度显示,用以给用户提示。其中最常见的两种是“环形进度条”和“水平进度条”。如下图所示:
代码如下:
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns: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="进度条显示"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="1000"
android:progress="100"
android:id="@+id/progressbar"
/>
<ProgressBar
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="1000"
android:progress="100"
android:secondaryProgress="300"
android:id="@+id/progressbar2"
/>
</LinearLayout>
这里介绍进度条事件的两种方法,一种是Activity直接继承Runnable,但是这种方法只能在虚拟机上执行,在真机上执行不了。第二种是利用Handler实现Runnable,代码如下:
privatevoidfindViews(){
progressbar=(ProgressBar)this.findViewById(R.id.progressbar2);
progressbar.setMax(1000);
progressbarMax=progressbar.getMax();
//newThread(this).start();
newThread(newRunnable(){
@Override
publicvoidrun(){
while(i++<progressbarMax){
i=dowork();
handler.post(newRunnable(){
publicvoidrun(){
progressbar.setProgress(i);
}
});
try{
Thread.sleep(100);
}catch(InterruptedExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
}).start();
}
publicintdowork(){
returni+=1;
}
SeekBar(拖动条):是ProgressBar的扩展,在其基础上增加了一个可以滑动的滑片(就是可以拖动的图标)可以触摸滑片并向左向右移动,SeekBar可以附加一个SeekBar.OnSeekBarChangeListener以获得用户的操作通知,如下图所示:
其代码如下:<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<SeekBar
android:id="@+id/seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="1000"/>
</LinearLayout>
ImageView:可以加载各种来源的图片,需要计算图片的尺寸,以便它可以在其它布局中能够使用,并提供例如缩放和着色各种显示项。
TabHost:提供选项卡的窗口视图容器,此对象包含两个子对象,一组是可以选择指定的Tab页的标签,另一组是FrameLayout用来显示该tab页的内容,即使使用的是单个元素,也最好把她放在容器对象的ViewGroup里。示例如下图: