进度条

一、ProgressBar控件:

布局文件代码:

<TextView  

    android:layout_width="fill_parent" 

    android:layout_height="wrap_content" 

    android:text="@string/hello"

    />

<ProgressBar

android:id="@+id/bar1"android:text="@string/hello"android:layout_width="fill_parent" 

android:layout_height="30dp"

style="@android:style/Widget.ProgressBar.Horizontal"

android:visibility="gone"

 />

<Buttonandroid:id="@+id/btn"android:text="单击增加" 

android:layout_width="fill_parent"android:layout_height="wrap_content"/>

Activity代码:

  btn1.setOnClickListener(new OnClickListener() {

           

           public void onClick(View v) {

              // TODO Auto-generated method stub

              

              if(i==0){

                  bar.setVisibility(ProgressBar.VISIBLE);

                  

              }else if(i<bar.getMax()){

                  bar.setProgress(i);

                  bar.setSecondaryProgress(i+10);

              }else{

                  bar.setVisibility(ProgressBar.GONE);

              }

              i+=10;

           }

       });

二、SeekBar

Activity代码:

public class SeekBarDemoActivity extends Activity {

    private SeekBar seekbar=null;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        seekbar=(SeekBar)findViewById(R.id.seekbar1);

        seekbar.setMax(100);

        seekbar.setOnSeekBarChangeListener(new ClickSeekBar());

    }

    class ClickSeekBar implements SeekBar.OnSeekBarChangeListener{

    @Override

    public void onProgressChanged(SeekBar seekBar, int progress,

            boolean fromUser) {

        // TODO Auto-generated method stub

        Toast.makeText(SeekBarDemoActivity.this, progress+"", Toast.LENGTH_LONG).show();

        

    }

 

    @Override

    public void onStartTrackingTouch(SeekBar seekBar) {

        // TODO Auto-generated method stub

        Toast.makeText(SeekBarDemoActivity.this, seekBar.getProgress()+"", Toast.LENGTH_LONG).show();

    }

 

    @Override

    public void onStopTrackingTouch(SeekBar seekBar) {

        // TODO Auto-generated method stub

        Toast.makeText(SeekBarDemoActivity.this, seekBar.getProgress()+"", Toast.LENGTH_LONG).show();

    }

    

    };

}

main.xml代码

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns: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"

    />

<SeekBar 

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:id="@+id/seekbar1"

    />

</LinearLayout>

 

posted @ 2011-08-29 23:07  rorshach  阅读(182)  评论(0编辑  收藏  举报