How to draw multiple layers over Custom ImageView background - android

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!

Related

How to create two circles of arcs moving by touch in Android

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

Android - How to create circle view with Android?

I am creating a View as below design here (like apple music).
pic 1:
pic 2:
The pink circle with physical interaction and fly. Can you suggest ways to make them?
Indeed, you should take a look at the custom view documentation.
What you should do to obtain such a result is to first override the onDraw() method in order to make your custom drawing inside.
Using the canvas, you will be able to create circle by calling :
canvas.drawCircle(x, y, radius, paint);
In order to make the circles look as you want, just take a look at the Paint documentation.
You can create as much circle as you want (the app efficiency is, of course, affected by the number of circle you draw).
With your custom view, you will be able to handle interactions easily, through the onTouchEvent() and to animate the circle modifying their properties over time.
You need to write own View as documented here https://developer.android.com/training/custom-views/index.html and then in your onTouchEvent() check if tap is inside or outside of area you consider checkable (in this case inside the given radius).

Drag and Drop Bitmap and TextView on Canvas- Android

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.

Android: Draw a moveable and sizeable rectangle on ImageView(Or any other bitmap compatible widget) and crop the selected region

I want to crop my image which is being displayed on an ImageView. How I want to go about it is that I want a re-sizable rectangle to be displayed on the image. That rectangle will have moveable corners (which I can drag around with touch) to increase/decrease its size. The image below illustrates a demo of something I would like to develop.
P. S. I am not quite sure how to phrase my question.
What I want:
http://imageshack.us/photo/my-images/832/customcropbox.jpg/
The final solution I came up with after ample research was:
Extend ImageView to make my own custom view.
#Override onDraw method and do my custom drawing there in that method.
Implement onTouchListener on the view to get the touch events and process them according to their position.
e. g.
I checked whether the touch was in the radius of the anchor point circle I drew around the movable rectangle that I was drawing in my overriden onDraw method.
Edit:
I am sorry guys I don't have that piece of code anymore, I came here after a very long time otherwise would have loved to help you out.
Heartache.

Dynamic Image in Android? (Beginner Question)

I would like to display a .png file from the R.drawable to the screen. Eventually I would like this image to be dynamic, meaning that it's position can move based on specified x,y coordinates.
I have looked into it but I am confused by the many options. Here are most of my questions:
What is the best data type/object to use for the situation?
What is the best way to instatiate the image?
Does it need to be a Drawable?
Does the Drawable then need its own View?
To display it, do I just add the new View to the main view?
I have experience with numerical method algorithms, but this is my first venture into graphics and I'm a bit overwhelmed, so any advice is greatly appreciated.
Edit - For the movement of the image, it will be moving around a lot, eventually as a user controlled movement.
As you note, there are many ways to do this. The "best" way depends on lots of things. If you want something like a ball bouncing around inside an area on the screen, the best approach might be to create a custom View and draw your .png in the onDraw() method at whatever coordinates you want. You can load your .png as a Bitmap using BitmapFactory.decodeResource().
Adding to what Ted said, if you want the image to later move around, you may want to draw it to a canvas. There are several useful draw methods for Canvas. SurfaceView is another option as well.
pic = BitmapFactory.decodeResource(getResources(), img);
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(pic, x, y, null);
//canvas.drawRect(x, y, right, bottom, null);
}

Categories

Resources