实现能定点移动的seekbar
布局xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns: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/seep" android:id="@+id/seep" /> <SeekBar android:id="@+id/seekbar" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
java代码
public class SeekBarActivity extends Activity { private SeekBar seekbar; private TextView tv ; int max=100; boolean flag = true; private Handler handler = new Handler(){ public void handleMessage(Message mes){ seekbar.setProgress(seekbar.getProgress()+1); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); seekbar = (SeekBar)findViewById(R.id.seekbar); tv = (TextView)findViewById(R.id.seep); seekbar.setMax(max); seep(); seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){ @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv.setText("进度为:"+progress+"%"); } @Override public void onStartTrackingTouch(SeekBar seekBar) { //停止刷新 flag=false; } @Override public void onStopTrackingTouch(SeekBar seekBar) { flag=true; handler.sendEmptyMessage(0); } }); } private void seep(){ DisThread dt = new DisThread(); dt.start(); } class DisThread extends Thread{ public void run(){ while(flag && seekbar.getProgress()<max){ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } handler.sendEmptyMessage(0); } } } }
相关推荐
zhonglinzhang 2012-06-05
ffnercn 2012-05-06
mpqitmp 2012-03-05
Drabandon 2014-09-30
jsxin0 2014-01-16
moira 2013-11-08
najiutan 2013-05-03
qinxu 2012-08-03
Tom天天 2012-04-26
zhaazha 2011-11-03
Nostalgiachild 2011-09-15
小迈 2011-09-06
AndroidGA 2011-09-02
androidty 2011-05-12
virusplayer 2010-12-24
yuemeng0 2010-07-12
冰川孤辰 2010-05-21