效果:

layout中的xml文件:

        
  1. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="fill_parent"
  3. android:layout_height="fill_parent"
  4. android:orientation="vertical">
  5. <TextView
  6. android:id="@+id/myTextView"
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text="当前进度:"/>
  10. <SeekBar
  11. android:id="@+id/mySeekBar"
  12. android:layout_width="fill_parent"
  13. android:layout_height="wrap_content"
  14. android:max="100"
  15. android:progress="30"
  16. />
  17. </LinearLayout>

Activaty.java文件:

        
  1. packagecom.cheng.seekbarproject;
  2. importandroid.os.Bundle;
  3. importandroid.app.Activity;
  4. importandroid.view.Menu;
  5. importandroid.widget.SeekBar;
  6. importandroid.widget.Toast;
  7. importandroid.widget.SeekBar.OnSeekBarChangeListener;
  8. importandroid.widget.TextView;
  9. publicclassSeekBarActivityextendsActivity{
  10. //定义组件
  11. privateTextViewmTextView;
  12. privateSeekBarmSeekBar;
  13. @Override
  14. protectedvoidonCreate(BundlesavedInstanceState){
  15. super.onCreate(savedInstanceState);
  16. super.setContentView(R.layout.main);
  17. //获得组件
  18. mTextView=(TextView)findViewById(R.id.myTextView);
  19. mSeekBar=(SeekBar)findViewById(R.id.mySeekBar);
  20. //设置进度条的监听器
  21. OnSeekBarChangeListenerosbcl=newOnSeekBarChangeListener(){
  22. @Override
  23. publicvoidonStopTrackingTouch(SeekBarseekBar){
  24. //TODOAuto-generatedmethodstub
  25. //当鼠标抬起的时候触发迟事件
  26. Toast.makeText(getApplicationContext(),"onStopTrackingTouch",Toast.LENGTH_LONG).show();
  27. }
  28. @Override
  29. publicvoidonStartTrackingTouch(SeekBarseekBar){
  30. //TODOAuto-generatedmethodstub
  31. //当鼠标点击下的时候触发该事件
  32. Toast.makeText(getApplicationContext(),"onStartTrackingTouch",Toast.LENGTH_LONG).show();
  33. }
  34. @Override
  35. publicvoidonProgressChanged(SeekBarseekBar,intprogress,
  36. booleanfromUser){
  37. //TODOAuto-generatedmethodstub
  38. //当进度条的值发生改变的时候触发
  39. mTextView.setText("当前进度:"+progress);
  40. Toast.makeText(getApplicationContext(),"当前进度:"+progress+"%",Toast.LENGTH_LONG).show();
  41. }
  42. };
  43. //绑定监听
  44. mSeekBar.setOnSeekBarChangeListener(osbcl);
  45. }
  46. @Override
  47. publicbooleanonCreateOptionsMenu(Menumenu){
  48. //Inflatethemenu;thisaddsitemstotheactionbarifitispresent.
  49. getMenuInflater().inflate(R.menu.main,menu);
  50. returntrue;
  51. }
  52. }

更多相关文章

  1. Android使用GPS定位
  2. Android为Notification加上一个进度条
  3. Android(安卓)密度转换多分辨率
  4. Android(安卓)判断是否为Wifi网络
  5. android 判断当前网络是否可用
  6. android 如何判断当前进程在主页面
  7. Android(安卓)BaseAdapter如何获得每一项并添加按钮事件
  8. android卸载应用的进度条
  9. android上方显示进度的进度条

随机推荐

  1. Try-Catch无法正确定位异常位置,我推荐2个
  2. java swing实现窗口最小化到托盘,点击托盘
  3. 制作酷炫的动态图表,竟然这么简单?
  4. 以为学习Python,自己就是数据分析师?
  5. Java 读写文件操作
  6. Elasticsearch搜索查询语法
  7. Shiro那些事儿(一): Shiro初探
  8. 利用shell脚本实现每隔60秒磁盘内存数据
  9. 不一样的享元模式(设计模式四)
  10. ElasticSearch实战系列四: ElasticSearch