我试图在SeekBar的拇指上方绘制一些文字,如上图所示。这个想法是当你沿着SeekBar移动拇指时,文字显示在拇指上方。我能够在拇指内绘制文字但是当我尝试在拇指外面绘制它时它不起作用。以下是我的代码:
public class MainActivity extends Activity {
SeekBar mybar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mybar = (SeekBar) findViewById(R.id.seekBar1);
mybar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// add here your implementation
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// add here your implementation
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
int value = seekBar.getProgress();
String valueString = value + "";
Paint paint = new Paint();
paint.setColor(Color.BLACK);
Bitmap b = Bitmap.createBitmap(600, 600,
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.drawText(valueString, 100, 100, paint);
seekBar.draw(canvas);
}
});
}
}
我是否必须覆盖onDraw方法而是这样做?