Draw Point on a Panning ImageView in Android - android

I have an ImageView panning by Matrix using
m.postTranslate(x, y);
command.
I found that I can get the touched x, y position based on ImageView coordinate
by using inverse() method.
But I cannot find that I can draw a point on the ImageView based on its coordinate.
Simply, I want to create a point of interest and save the position on a map (ImageView),
and draw them together preserving the position of the point.
Please see also the image below that describes what I want to do.
http://img197.imageshack.us/img197/3214/qwms.png
If anyone can give me some clue, I will be very appreciated.
Thank you.

you need use a custom view for use the override metod onDraw()..thats u need for draw

Related

making a view move from one coordinate to another coordinate in android studio

I have an image view and a photoview in android studio. The photoview is set to an image bitmap. I want to initially place a view on a specific x, y coordinate on top of the photoview but I want to place the view depending on the matrix of the image bitmap, not the photoview. Then I want to make the image view translate from 1 x, y coordinate to another coordinate. what is the best way to do this?
Your question is a little vague but looking at the title of the question, to move a view to the coordinates of another view, you could set the x and y to the values of the view you want to move to. Let's say you want to move imagview1 to the point where imageview2 is:
imageview1.animate().x(imageview2.getX()).y(imageview2.getY());
Or if you don't wanna animate it just remove animate():
imageview1.setX(imageview2.getX());```
Could you elaborate more or in this case, clearly

Simultaneously move six points in circular paths around their own orbital centers

Suppose I have six points drawn in a Canvas along the circumference of a circle, in the pattern of a hexagon.
I want to simultaneously move and re-draw each of these six points in a small circular path - for example, each point moves along the circumference of a circle with 1/10th the radius of the larger circle.
I'm a little lost on how to do this with Canvas and onDraw and I don't know if better solutions exist. How would you do this?
Some answers have at least pointed me toward this which shows how a point might move along a circular path, but I don't know how to implement it for this situation:
for (double t = 0; t < 2*Pi; t += 0.01)
{
x = R*cos(t) + x_0;
y = R*sin(t) + y_0;
}
Thank you!
Here's one approach:
Start with a custom view that extends View and overrides onDraw. You are on the right track with using the drawing functions of Canvas.
Give your custom view a field to hold the current angle:
private float mTheta;
Then add a method like:
public void setTheta(float radians) {
mTheta = radians;
invalidate();
}
Then in onDraw, use the current value of mTheta to calculate the position of your points.
Of course, with the custom view you might need to handle sizing with an onMeasure override and possibly some layout with an onLayout override. If you set the dimensions of the view to an absolute dp value, the default behavior should work for you.
Doing it this way will set you up to override onTouch and allow user interaction to move the graphics, or use a ValueAnimator to cycle from 0 to 2π calling setTheta from within your AnimatorUpdateListener.
Put some code together and when you get stuck, post another question. If you add a comment to this answer with a link to the new question, I'll take a look at it.

How to check touch on a bitmap

I want to know if there is a way to check if the user touched the bitmap, ofcourse im talking about an image without background, like a circle, a triangle and so on.
Thanks!
image without background, like a circle, a triangle and so on
then you should probably override View's onTouch, retrieve x and y from the touch event you got as parameter and compare it with the coords of the shape you drawn. The easiest way is to use Rect.contains(int x, int y)

How do i animate an image in android so it follows a path made of several coordinate?

I found out that the movement of an image between two point can be achieved with this simple code:
ImageView image_to_move = (ImageView) findViewById(R.id.image_to_move);
TranslateAnimation animation = new TranslateAnimation(50, 100, 50, 100);
animation.setDuration(5000);
image_to_move.startAnimation(animation);
The image is an ImageView set initially in position (0,0) inside a FrameLayout and the code move it from the point (50,50) to (100,100).
What if i have to move it on a path, made of several point, in the form of absolute coordinate (x,y)? For example, move from (50,50) to (75,75) then to (100,100)
There's a way to pass to the translating function an array of coordinate or i have simply to iterate the animation for every couple of points?
Btw, i saw that if i don't initially locate the image in (0,0) the function moves the image in a weird way, like the coordinate i give are not read as absolute. Am i missing something?
EDIT: The last thing happens when i pass as parameters to the TranslateAnimation something like "n92.getX()" where n92 is a button on my frame layout, from which position i want the animation to start.
DETAIL: Just to understand better the problem: I am implementing the animation of a point moving on a map, to show the user how to get from one point to another of a map. That's why i have absolute coordinate (the reachable points) that must be followed (you can't arrive from one point to another without following a precise path on the map)
to do so you need to Calculate the position on a quadratic bezier curve. try this answer it might be work for you

Draw image in activity android

I have a activity where I have two imageViews. In onTouch I recognize which imageView was clicked. Now I have a question. How I can draw new very small image in place where I clicked. I know that onTouch i have getX() and getY() and I save this position when I touch the screen, but I don't know how I can draw image in place where I clicked. My image is in drawable resources. I need to use canvas or is better way. I need draw this picture and after that I need run animation this image.
edit1: How can I set positionX and positionY my image. I have position where I click but I don't know how I can set image in this coordinates.
you should have a image view with visible attribute of FALSE and after touch (or any event you want) set three attribute : visible = true; x = getX() and y = getY();
is it enough or explain more?
I see the following approach.
Replace the ImageView by a custom view derived from ImageView.
Override onDraw.
call super.onDraw to draw the image
paint your image using onDraw's canvas at the last touch position.
each time you get a touch, you need to invalidate the custom view

Categories

Resources