步骤一、在main.xml中加入seekbar控件和一个文本显示控件,加入相应控件后的内容如下:
<?xml version="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<SeekBar android:id="@+id/playseekBar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:max="300"
></SeekBar>
<TextView android:text="TextView"

android:id="@+id/percenttextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22px"
></TextView>
</LinearLayout>
步骤二、编写activity类,类名为:SeekBarActivity,其内容如下:
package com.appTest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
public class SeekBarActivity extends Activity {
SeekBarplayseekBar = null;
TextViewpercnet = null;
@Override
public voidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
playseekBar = (SeekBar) findViewById(R.id.playseekBar);
playseekBar.setOnSeekBarChangeListener(newSeekBarListener());
percnet = (TextView) findViewById(R.id.percenttextView);
}
privateclass SeekBarListener implementsSeekBar.OnSeekBarChangeListener
{
@Override
public voidonProgressChanged(SeekBar seekBar, int progress,
booleanfromUser) {
// TODOAuto-generated method stub
percnet.setText("change:"+playseekBar.getProgress());
}
@Override
public voidonStartTrackingTouch(SeekBar seekBar) {
// TODOAuto-generated method stub
percnet.setText("start:"+playseekBar.getProgress());
}
@Override
public voidonStopTrackingTouch(SeekBar seekBar) {
// TODOAuto-generated method stub
percnet.setText("stop:"+playseekBar.getProgress());
}
}
}
步骤三、运行程序,模拟器中的运行截图如下: