Android组件(三)

Progress(进度条):打开文件等的进度显示,用以给用户提示。其中最常见的两种是“环形进度条”和“水平进度条”。如下图所示:

 

代码如下:

<?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="进度条显示" />

    <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,代码如下:

private void findViews() {

progressbar = (ProgressBar) this.findViewById(R.id.progressbar2);

progressbar.setMax(1000);

progressbarMax = progressbar.getMax();

// new Thread(this).start();

new Thread(new Runnable() {

@Override

public void run() {

while (i++ < progressbarMax) {

i = dowork();

handler.post(new Runnable() {

public void run() {

progressbar.setProgress(i);

}

});

try {

Thread.sleep(100);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}).start();

}

public int dowork() {

return i += 1;

}

SeekBar(拖动条):ProgressBar的扩展,在其基础上增加了一个可以滑动的滑片(就是可以拖动的图标)可以触摸滑片并向左向右移动,SeekBar可以附加一个SeekBar.OnSeekBarChangeListener以获得用户的操作通知,如下图所示:

其代码如下:<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns: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里。示例如下图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值