I am able to resize a drawn ShapeDrawable but it Creates another shape with the following code how can I just resize the original ShapeDrawable我正在编写一个绘图应用程序,并且已经停留了几天
任何帮助将不胜感激
即使是在正确的方向小推动请。
public void Resize(Context context){
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
//this.setOnClickListener(this.mDrawablecircle);
int x =Integer.parseInt("0");
int y =Integer.parseInt("0");
int cirw =Integer.parseInt("20");
int cirh =Integer.parseInt("20");
mDrawablecircle.getPaint().setStyle(Style.valueOf(Shapestoollistactivity.mf));
mDrawablecircle.getPaint().setColor(ColorPickerActivity.thecolor);
mDrawablecircle.getCurrent().setBounds(x, y, x + cirw, y + cirh);
mDrawablecircle.draw(mCanvas);}/ /更新这是我最终做的仍然不是100%
//但有些工作可能会帮助其他人
public void Resize(int newWidth){
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
int x = (int) mPosX;
int y = (int) mPosY;
width = mDrawablecircle.getBounds().width();
height = mDrawablecircle.getBounds().height();
float scaleWidth = ((float) newWidth) / width;
float ratio = ((float) mDrawablecircle.getBounds().width()) / newWidth;
int newHeight = (int) (height / ratio);
float scaleHeight = ((float) newHeight) / height;
matrix.setTranslate(mPosX+40,mPosY+40);
matrix.postScale(scaleWidth, scaleHeight);
postInvalidate();}
// and in In onDraw
// I Changed this: mCanvas.drawBitmap(mBitmap,0,0, mPaint);
// to: mCanvas.drawBitmap(mBitmap,matrix, mPaint);
hope this helps some one else Im sure there is a better solution
but I cant seem to find a better one as of yet feel free to chime in and
correct me Please this at least will do the resize of a shape drawable without
creating a new one but it resizes the whole canvas NOT WHAT I WAS AFTER
I would like to be able to resize individuale shapedrawables
Which are created from java code not xml or from a resource.