2
 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.             
4

1 に答える 1

0

このように mDrawableCircle で draw を呼び出す代わりに、次のようにします。あなたのクラスはカスタムビューだと思います。

    public void Resize(Context context) {
          .....
       invalidate();
    }

    public void onDraw(Canvas canvas) {
       super.onDraw(paint);
       //Do the drawing of the drawable here. 
    }
于 2012-07-20T05:40:59.647 に答える