I am trying to implement the drag and drop functionality in Android. I have a Custom View that overrides the onDraw(Canvas canvas) method to draw a Bitmap on a canvas that acts as my background. Then, I have created it so I can select different colors and paint in this area.
Now, I am trying to add the ability to select photos from the gallery and place them into the canvas. Also, I want to add the ability to create and add textboxes to the canvas area as well. How would I implement this?
I have read through several tutorials looking to create multiple views that are placed in a Canvas, but have not found an example of this being one. Am I understanding the Canvas and View classes incorrectly and is there a simpler way to do this? Any help is very much appreciated. Thank you.
Related
In some paint apps or note taking apps, they will allow you to add text and images in addition to drawing stuff.
Now I know that I can create a custom view and override on touch events and build paths and draw them on canvas.
But what I don't know is this: In apps like mentioned above I am confused if they add images as image views or they add images directly drawn on canvas.
I mean do they create new imageview and set the gallery image to it, or they simply add the image directly to the canvas.
Any thoughts?
Thanks.
They draw it directly to the Canvas. Notice the Canvas class (which is how Views draw) has a drawBitmap and drawText functions. Generally in a drawing app the entire area you draw on will be just 1 view.
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 am creating a simple free hand drawing app. In my layout, i have two images placed. I need to select the correct image, by drawing a free hand circle around the image. As i am new to android, i don't know the correct way to do it. I tried some ways to draw free hand drawings like, calling a drawing view class and using the onDraw method to paint the path using canvas, but for that i had to kept my setContentView() to drawing view class. But I want to use my layout with images as setContentView() and make free hand drawings to draw around the images. Can somebody help me? Thank you in advance.
I am new to android, spent whole day trying to figure this out including endless digging in this website, and still can't figure it out. So usually I don't ask questions here but decided to go for it
I am using a Custom ImageView that supports pinch-zoom from here
Basically after I load the view with my background image (a map), I want to have a red dot/cross to mark the center of the screen. Then I want the user to press a button, and mark the current place with some special mark (e.g. small circle/rectangle). Thus I want to allow all the places the user pressed a button on when pointed at the center of the imageview to be marked (and stay like this). Here's an example of how it may look
I am using the custom ImageView in my main activity(works well)
As advised I've overridden the onDraw method of my custom ImageView:
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint.setColor(Color.RED);
canvas.drawCircle(mWidth/2, mHeight/2, 2, paint);
}
And that created indeed the red(this was my paint style) circle. But now I can't come up with the method to draw the other circles. I tried to follow some advices to recreate each time the Bitmap, set the image to it, then draw whatever and set it on a canvas but that doesn't work because the coordinates of the center have changed already - the center is dynamic(and perhaps for other reasons too - Maybe The marked places should be on a different layer)
Thanks for any help!
How to use Customized fonts on Canvas?
I have customized view (PIECHART DRAWN ON CANVAS) on left side of the screen and list view on right of the screen. When ever I touched on the canvas list view values has to be changed. is it possible. My listview is in Activity A class.And view is in B class.
I have piechart with n no of arcs. On tapping on that i have to known which arc is tapped. Is there any formula for it. (Like for rectangle basing on left,top and width hegiht we can check.)
In the drawText function in the canvas you have to provide a Paint object. Well the paint object has a function that accepts a typeface and it is called setTypeface(). Look more into that function and its uses and perhaps this tutorial and you will see that it is rather straightforward to use any font that you like in Canvas.
My advice would be to make questions 2 and 3 separate questions in their own right and improve your explanation of what you want to happen.