1

在此处输入图像描述

我正在尝试在 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 方法并改为这样做?

4

0 回答 0