[安卓] 5、SeekBar拖动条

 

 


越来越发现这些控件用法大同小异了,这里注意几个函数:seekBar.setSecondaryProgress(0);设置初始进度为0,总共为0~99,对其监听用setOnSeekBarChangeListener。

 1 public class MainActivity extends Activity {
 2     private SeekBar seekBar;
 3     private TextView tv;
 4 
 5     @Override
 6     public void onCreate(Bundle savedInstanceState) {
 7         super.onCreate(savedInstanceState);
 8         setContentView(R.layout.main);
 9         seekBar = (SeekBar) findViewById(R.id.seekbar);
10         tv = (TextView) findViewById(R.id.tv);
11         seekBar.setSecondaryProgress(0);
12         seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
13             //当用户对拖动条的拖动的动作完成时触发
14             @Override
15             public void onStopTrackingTouch(SeekBar seekBar) {
16                 tv.setText("<拖动条>完成拖动"); 
17             }
18             //当用户对拖动条进行拖动时触发
19             @Override
20             public void onStartTrackingTouch(SeekBar seekBar) {
21                 tv.setText("<拖动条>拖动中...");  
22             }
23             //当拖动条的值发生改变的时触发
24             @Override
25             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
26                 tv.setText("当前<拖动条>的值为:"+progress);
27             }
28         });
29     }
30 }

 

 

 

本文链接:http://www.cnblogs.com/zjutlitao/p/4229808.html

更多精彩:http://www.cnblogs.com/zjutlitao/

 

posted @ 2015-01-16 21:41  beautifulzzzz  阅读(723)  评论(0编辑  收藏  举报