对此有何帮助?当我尝试使用搜索栏来更改画笔宽度时出错。 错误行是UNDER setStrokeWidth,说“不适用于参数(字符串)”
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drawing_activity);
setCurrentPaint();
currentBrush = new PenBrush();
drawingSurface = (DrawingSurface) findViewById(R.id.drawingSurface);
drawingSurface.setOnTouchListener(this);
drawingSurface.previewPath = new DrawingPath();
drawingSurface.previewPath.path = new Path();
drawingSurface.previewPath.paint = getPreviewPaint();
redoBtn = (ImageButton) findViewById(R.id.redoBtn);
undoBtn = (ImageButton) findViewById(R.id.undoBtn);
redoBtn.setEnabled(false);
undoBtn.setEnabled(false);
//SEEKBAR THICKNESS CHANGE
//
//
SeekBar seekBar = (SeekBar)findViewById(R.id.seekBar);
final TextView seekBarValue = (TextView)findViewById(R.id.seekValue);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
seekBarValue.setText(String.valueOf(progress));
**currentPaint.setStrokeWidth(String.valueOf(progress));**
}
@Override
public void onStartTrackingTouch(SeekBar seekBar){
}
@Override
public void onStopTrackingTouch(SeekBar seekBar){
}
});
}
//END SEEKBAR THICKNESS
private void setCurrentPaint(){
currentPaint = new Paint();
currentPaint.setDither(true);
currentPaint.setColor(0xFFFFFFFF);
currentPaint.setStyle(Paint.Style.STROKE);
currentPaint.setStrokeJoin(Paint.Join.ROUND);
currentPaint.setStrokeCap(Paint.Cap.ROUND);
currentPaint.setStrokeWidth(3);
}
private Paint getPreviewPaint(){
final Paint previewPaint = new Paint();
previewPaint.setColor(0xFFC1C1C1);
previewPaint.setStyle(Paint.Style.STROKE);
previewPaint.setStrokeJoin(Paint.Join.ROUND);
previewPaint.setStrokeCap(Paint.Cap.ROUND);
previewPaint.setStrokeWidth(3);
return previewPaint;
}
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
drawingSurface.isDrawing = true;
currentDrawingPath = new DrawingPath();
currentDrawingPath.paint = currentPaint;
currentDrawingPath.path = new Path();
currentBrush.mouseDown(currentDrawingPath.path, motionEvent.getX(), motionEvent.getY());
currentBrush.mouseDown(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
}else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){
drawingSurface.isDrawing = true;
currentBrush.mouseMove( currentDrawingPath.path, motionEvent.getX(), motionEvent.getY() );
currentBrush.mouseMove(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
}else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
currentBrush.mouseUp(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
drawingSurface.previewPath.path = new Path();
drawingSurface.addDrawingPath(currentDrawingPath);
currentBrush.mouseUp( currentDrawingPath.path, motionEvent.getX(), motionEvent.getY() );
undoBtn.setEnabled(true);
redoBtn.setEnabled(false);
}
return true;
}
答案 0 :(得分:0)
替换currentPaint.setStrokeWidth(String.valueOf(progress));用:
currentPaint.setStrokeWidth(progress);
您正在尝试将字符串传递给setStrokeWidth,这就是您收到错误的原因。希望有所帮助。祝你好运!
答案 1 :(得分:0)
setStrokeWidth
采用float
参数,而不是String
。使用currentPaint.setStrokeWidth(progress);