Android控件开发之SeekBar

//SeekBar:用户调整进度的指示进度条
//例如我们用播放器看电影的时候,经常会向前移动进度,SeekBar就是这个功能,

//它类似一个进度条,但是调节器,可以被用户移动


SeekBar效果

 


本程序main.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:id="@+id/text"  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"/>

<SeekBar
    android:id="@+id/seekbar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:max="500"/>
<!-- android:max="500" 设置seekbar显示的最大值 -->

</LinearLayout>




本程序java源码

public class SeekBarActivity extends Activity 
{
    private TextView textview = null;
    
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        SeekBar seekbar = (SeekBar)findViewById(R.id.seekbar);
        textview = (TextView)findViewById(R.id.text);
        seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() 
        {


			public void onStopTrackingTouch(SeekBar seekBar) 
			{
			// TODO Auto-generated method stub
			}
			public void onStartTrackingTouch(SeekBar seekBar) 
			{
			// TODO Auto-generated method stub
			}
			public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) 
			{
			     textview.setText("value:" + progress);
			     seekBar.setSecondaryProgress((progress + seekBar.getMax()) /2);
			}
		});
	}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章