2 Replies - 2136 Views - Last Post: 31 March 2012 - 10:01 AM

#1 MattyDanielle   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 27-March 12

How can i scale a canvas to fit everything in it.

Posted 29 March 2012 - 07:44 PM

Hi guys I just started using the android SDK so I started making this vector calulator app. The only thing left that I want to do is scale the canvas somehow based on how far outside of the screen the vectors go. As you can see from this screenshot:
Posted Image

It starts leaving the screen. Can someone tell me how to properly use something like Canvas.scale to do this without moving the centerpoint of the canvas. I have the top, bottom, left, and right of the vector space too that will help me figure out how much it needs to be scaled. THanks!

Is This A Good Question/Topic? 0
  • +

Replies To: How can i scale a canvas to fit everything in it.

#2 H3R3T1C   User is offline

  • Android Expert
  • member icon

Reputation: 278
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: How can i scale a canvas to fit everything in it.

Posted 29 March 2012 - 10:44 PM

Well what you could do is use a drawable. By using a drawable you can re-size it to fit everything by settings it bounds. I'm assuming the area your drawing your vectors is a class that extends view? Well with the drawable you can still use canvas. You can replace your drawing view with an ImageView and sets its wight to 1, width to match parent and height to 0dp (that is assuming your using xml layouts to construct the view and that the parent of the drawing view your using is a LinearLayout). You also need to set the scale type for the ImageView to FIT_CENTER and set the imageDrawable to your class that exends Drawable. I hope this makes sense but if it does not I will gladly provide some code to show what I mean.
Was This Post Helpful? 0
  • +
  • -

#3 MattyDanielle   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 27-March 12

Re: How can i scale a canvas to fit everything in it.

Posted 31 March 2012 - 10:01 AM

The problem I am having is that I was using a VectorView instance i created in the code and just did addView(VectorView) I spent a few hours last night going through google trying to figure out how to use a custom view in the XML layout but I had no luck. Can you possibly help me with this?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1