1.样式xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<SeekBar
android:id="@+id/progress"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/text1"
android:maxHeight="2dp"
android:minHeight="2dp"
android:paddingBottom="3dp"
android:paddingLeft="12dp"
android:max="30"
android:min="1"
android:paddingRight="12dp"
android:paddingTop="10dp"
android:progressDrawable="@drawable/layer_progress"
android:thumb="@drawable/shape_circle" />
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="left"
android:padding="6dp"
android:text="1"
android:textColor="#00BFFF"
android:textSize="20dp" />
</LinearLayout>
2.后台代码
private SeekBar seekBar;
private TextView textView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar = (SeekBar) findViewById(R.id.progress);
textView = (TextView) findViewById(R.id.text1);
seekBar.setProgress(15);//设置节点初始位置
textView.setText("15");//设置节点初始值
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// 当拖动条的滑块位置发生改变时触发该方法,在这里直接使用参数progress,即当前滑块代表的进度值
//textView.setText("Value:" + Integer.toString(progress));
//Toast.makeText(MainActivity.this, "正在滑动!"+ progress, Toast.LENGTH_SHORT).show();
textView.setText(Integer.toString(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
//Log.e("------------", "开始滑动!");
Toast.makeText(MainActivity.this, "开始滑动!", Toast.LENGTH_SHORT).show();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
//Log.e("------------", "停止滑动!");
Toast.makeText(MainActivity.this, "停止滑动!", Toast.LENGTH_SHORT).show();
}
});
}
|