shape固定宽高矩形android,如何通过代码直接调整Android ShapeDrawable的大小而不创建另一个...

作者分享了一段关于如何在绘图应用程序中仅缩放已绘制的ShapeDrawable,避免创建新形状的问题。他们尝试了多种方法,包括设置OnTouchListener和修改onDraw函数,目标是实现精确的形状缩放而不影响整个画布。如果你也面临类似挑战,这段内容可能对你有帮助。
摘要由CSDN通过智能技术生成

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值