I am trying to create a circle wheel divided in a fixed number of sections. Each section should be clickable.
How I approach this? Should I make an image and set as a background or is there a way to draw all parts in java?
Shortly:
Create .png with pizza.
Create new widget, extending View.
Override onDraw() and draw it to canvas with some rotation. Optionally you can draw lines with java if it's margeritta not a pepperoni.
If necessary - change rotation call invalidate() to redraw view
Add onTouch() listener, get position ot tap, calculate what sector was touched.
One Solution would be to draw different paths for each piece on a Canvas (path.lineTp and path.addCircle - think so). Then you can add ClickListeners to the paths and they will be clickable....
Related
I need to draw a reverse Z shaped figure like this in Android using View element. I can't use any image. I need to achieve it using View.
Explanaton of the attached image :
The rectangle box represents the screen of the mobile device.
The reverse Z shaped figure is what I need to draw using View; such that the center of the slanting line ("/") should coincide with the center of the device screen. The other two lines should be of same length as well.
The figure should be relative to the screen sizes.
Thanks!
Create a custom View (a class that extends View)
Call setWillNotDraw(false) in its constructor (to make sure your custom onDraw will be called)
Create custom onLayout method in which you will calculate positions of those four points (store them as fields of your custom View):
Create custom onDraw method in which you will use various Canvas methods to draw your things.
Frame: use drawRect with Paint object that has stroke
"The reverse Z shaped": there many ways to draw this thing e.g. use drawLines to draw lines between points calculated in 3.
can someone please give me advice or instruction how to create custom view, which draws two circles with different (or maybe same) count of arcs, and the most important, enable rotating each circle independently anti/clockwise by touch move? But no moving on center hole.
I think image describe it best
rotating circles
I needed something like this and I can't find a component so I implement one.
A custom view that uses Canvas in onDraw method .
For each wheel you can add a list of String to show in each section and a list of Paint to paint that section .
https://github.com/mehdi-azizi/Nested-Wheels-View/blob/master/NestedWheelApp/app/src/main/java/com/ma/nestedwheels/NestedWheelsView.java
I want to draw a big image on canvas, and after that I want to move that canvas so it shows me different part of this image. Without repainting it (or eventually repainting only the needed part). How is it done in android?
Check this method. All you need to do is to specify horizontal and vertical distance to move your canvas. You can also scale, rotate or even apply custom matrix on canvas. This tutorial also might be helpful.
I have an android app I have written, that basically has a custom overlay, in this overlay I have overwritten the DRAW method to draw something on a canvas and at the end of my DRAW override, I call the super DRAW passing in the canvas I have painted.. the result is, every time the map is modified in anyway my custom overlay is redrawn as expected.
Now, I am trying to accomplish the same thing on iPhone and am getting a little confused.
Basically I need something drawn in the top right corner of the map every time a redraw occurs of the map. The drawin will change change with every update as well so can't simply be put a view over the map and pass touches through etc.
So, I guess the question is, what is the euivalent of the DRAW method in iOS.. how would I roughly accomplish this same thing? There are MKOverlayView in the API, but there seem to be some significant differences.. So, how do I put something say at 10x10 over the map, whos size is variable and make sure every time the map is moved, scaled or otherwised interacted with this object is redrawn at location 10x10 on the screen.
The docs for MKMapView state that you should not subclass MKMapView, so you can't / shouldn't override the drawRect method. You could add a UIView, though, and override drawRect to do your custom drawing.
I know how to draw paths on a canvas and understand how to undo/redo. But now I want to draw shapes (lines, circles, rectangles) that dynamically resize depending on how I drag them - just like we have in MS Paint.
If I use "drawLine", the line is there permanently with no way of erasing it and redrawing it to my new finger location. Same with circle as I want the circle to constantly change width as I drag my finger. So the old one has to erased (keeping all the other paths on the bitmap intact) and the new one drawn in its place.
Been searching a lot for this, but haven't come across how t do it. Maybe I'm using the wrong keywords, but I don't know. Any pointers?
Each time you move the finger, call the underlying view's invalidate() function, it will trigger erasing the entire background
public void invalidate ()
Since: API Level 1
Invalidate the whole view. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future. This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().
Then redraw your shape based on your finger's new position.
Managed to do it. I misunderstood the way the offscreen drawing thing worked. The idea is to write to the bitmap only after you have the shape you want - ie on "touch up". Till then, draw the shape using the "canvas" object in on Draw...