android学习日记03--常用控件progressbar/seekbar
5、progressbar
进度条,比较常用的组件,一般有圆形和条形两种;
默认进度条是圆形的
小圆型进度条:
style="?android:attr/progressBarStyleSmall"
大圆形进度条:
style="?android:attr/progressBarStyleLarge"
条形进度条:
style="?android:attr/progressBarStyleHorizontal"
android:max="100" --最大值
android:progress="50"
--初始值
android:secondaryProgress="60" --次进度条值
例子:
新开个线程,让条形进度条从最小增到最大,再减到最小
1 public class MainActivity extends Activity implements Runnable{ 2 3 private Thread td; 4 private ProgressBar pb; 5 private boolean stateChange; 6 7 @Override 8 protected void onCreate(Bundle savedInstanceState) { 9 super.onCreate(savedInstanceState); 10 setContentView(R.layout.activity_main); 11 12 pb = (ProgressBar)findViewById(R.id.pd); 13 td = new Thread(this); 14 15 td.start(); 16 } 17 18 19 @Override 20 public boolean onCreateOptionsMenu(Menu menu) { 21 // Inflate the menu; this adds items to the action bar if it is present. 22 getMenuInflater().inflate(R.menu.main, menu); 23 return true; 24 } 25 26 27 @Override 28 public void run() { 29 // TODO Auto-generated method stub 30 while(true) { 31 int current = pb.getProgress(); 32 int max = pb.getMax(); 33 int securrent = pb.getSecondaryProgress(); 34 35 if (stateChange == false) { 36 if(current >= max) { 37 stateChange = true; 38 }else { 39 pb.setProgress(current+1); 40 pb.setSecondaryProgress(current+1); 41 } 42 }else { 43 if(current <= 0) { 44 stateChange = false; 45 }else { 46 pb.setProgress(current-1); 47 pb.setSecondaryProgress(current-1); 48 } 49 } 50 51 try { 52 td.sleep(50); 53 } catch (Exception e) { 54 e.printStackTrace(); 55 } 56 } 57 } 58 59 }
6、seekBar
拖动条
监听事件:
1 @Override 2 public void onStopTrackingTouch(SeekBar seekBar) { 3 // TODO Auto-generated method stub 4 tv.setText("拖动完成..."); 5 } 6 7 @Override 8 public void onStartTrackingTouch(SeekBar seekBar) { 9 // TODO Auto-generated method stub 10 tv.setText("拖动中..."); 11 } 12 13 @Override 14 public void onProgressChanged(SeekBar seekBar, int progress, 15 boolean fromUser) { 16 // TODO Auto-generated method stub 17 tv.setText("当前拖动条值为:"+progress); 18 }
类似长型的进度条,只是可以手动拖到,
也有
android:max="100" --最大值
android:progress="50"
--初始值
android:secondaryProgress="60" --次进度条值
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。