//例如我們用播放器看電影的時候,經常會向前移動進度,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);
}
});
}
}