八, SeekBar 音频播放拖拽进度条
>
android:progress="40" 第一进度
android:secondaryProgress="50" 第二进度
>使用: setOnSeekBarChangeListener
<span style="font-size:18px;">package com.fmy.a; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Toast; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo_textview); SeekBar sb = (SeekBar) findViewById(R.id.sb);
//用户点击不会触发此回调接口
sb.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "嘿嘿", 0).show();
}
});
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { //停止拖动音频条
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
System.out.println("停止拖动");
}
//开发拖动音频条
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
System.out.println("开始拖动音频条");
}
//音频条改变 fromUser是否是用户改变的状态 progress 当前进度
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
System.out.println("音频条改变"+fromUser);
}
}); } }</span>
<span style="font-size:18px;"><span style="display: none; width: 0px; height: 0px;" id="transmark"></span><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- android:progress="100" 设当前进度
android:max="100" 最大进度 >缺省为100
android:secondaryProgress="40" 第二进度条位置
-->
<SeekBar
android:id="@+id/sb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="10"
android:secondaryProgress="40"
/> </LinearLayout></span>