私はandroid.でペイントアプリを作成していますが、clickListenersでSTROKE幅またはブラシサイズの増減を変更したいという1つの問題があります。描画ブラシの幅が変更されました。問題を解決するために何ができますか。助けてください。これは私のコードです
int Stork_Width=0;
but1 = (Button) dialog.findViewById(R.id.but1);
// if button is clicked, close the custom dialog
but1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//idd=mMaindialog.get(position).imagename;
Stork_Width=10;
mPaint.setStrokeWidth(Stork_Width);
dialog.dismiss();
}
});
but2 = (Button) dialog.findViewById(R.id.but2);
// if button is clicked, close the custom dialog
but2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Stork_Width=15;
mPaint.setStrokeWidth(Stork_Width);
dialog.dismiss();
}
});
but3 = (Button) dialog.findViewById(R.id.but3);
// if button is clicked, close the custom dialog
but3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Stork_Width=25;
mPaint.setStrokeWidth(Stork_Width);
dialog.dismiss();
}
});
now i create the method of Brushes :
and strore the path in Hashmap also:
private Map<Path, Integer> colorwidth = new HashMap<Path, Integer>();
private Paint createBrush(final int width) {
// TODO Auto-generated method stub
mPaint1 = new Paint();
mPaint1.setColor(colorPicked);
mPaint1.setAntiAlias(true);
mPaint1.setDither(true);
mPaint1.setStyle(Paint.Style.STROKE);
mPaint1.setStrokeJoin(Paint.Join.ROUND);
mPaint1.setStrokeCap(Paint.Cap.ROUND);
mPaint1.setStrokeWidth(width);
return mPaint1;
}
ontouch activity::
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// touch_start(x, y);
// invalidate();
undonePaths.clear();
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
invalidate();
break;
case MotionEvent.ACTION_MOVE:
// touch_move(x, y);
// invalidate();
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
mX = x;
mY = y;
}
invalidate();
break;
case MotionEvent.ACTION_UP:
// touch_up();
// invalidate();
mPath.lineTo(mX, mY);
mMaindialog.add(mPath);
colorsMap.put(mPath, slll);
colorwidth.put(mPath, Stork_Width);
mPath = new Path();
mPath.reset();
invalidate();
break;
}
return true;