Solved

x y coordinates  animation

Posted on 2012-03-28
3
1,267 Views
Last Modified: 2012-04-17
I can display an animation frame by frame but it doesnt move.


If I have an image view , how do I get the x,y coordinates of the image ?
How do I set the new x y values of this image?

MY code works with frame anmation only.

private void animate() {
            ImageView imgView = (ImageView) findViewById(R.id.animationImage);
            // imgView.setVisibility(ImageView.VISIBLE);
            imgView.setBackgroundResource(R.drawable.ani);
            

            AnimationDrawable frameAnimation = (AnimationDrawable) imgView
                        .getBackground();

            if (frameAnimation.isRunning()) {
                  frameAnimation.stop();
                  b.setText("Start");
            
            } else {
                  frameAnimation.start();
                  b.setText("Stop");
            }
      }
0
Comment
Question by:jagguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 37781673
0
 
LVL 1

Expert Comment

by:garikapatisuresh
ID: 37782262
Based on your I understand that you want to move an object from one place to another.

I have created one sample and attached below. I think it will full fill your requirement.
AnimationSampleActivity.java
Ball.java
AndroidManifest.xml
0
 
LVL 8

Accepted Solution

by:
Santhana earned 500 total points
ID: 37785715
Hi jagguy,

1) I can display an animation frame by frame but it doesnt move.

You are using animation drawable to animate the ImageView.

It is used to create  frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background

http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
It will not be used to move the view object.

2) how do I get the x,y coordinates of the image ? How do I set the new x y values of this image?

http://stackoverflow.com/questions/3619693/how-to-get-views-position

The geometry of a view is that of a rectangle.
A view has a location, expressed as a pair of left and top coordinates,
and two dimensions, expressed as a width and a height.

The unit for location and dimensions is the pixel.
It is possible to retrieve the location of a view by invoking the methods
getLeft()  - Returns the left, or X, coordinate of the rectangle representing the view.
getTop() - Returns the top, or Y, coordinate of the rectangle representing the view.
getRight() and getBottom() - These methods return the coordinates of the right and bottom edges of the rectangle representing the view.
calling getRight() is similar to the following computation: getLeft() + getWidth()
These methods both return the location of the view relative to its parent. For instance, when getLeft() returns 20, that means the view is located 20 pixels to the right of the left edge of its direct parent.
------------------------------------------------------------------------------------------------------------------------------

If you want to move the view by using Tranlate Animation  use following code

Animation lTraslateAnimation = new TranlateAnimation()0 , 0, 0, 500);
lTraslateAnimation.setDuration(2000);
lTraslateAnimation.setFillAfter(true);
lTraslateAnimation.setRepeatCount(-1);
lTraslateAnimation.setRepeatMode(Animation.REVERSE);
 imgView .startAnimation(lTraslateAnimation);

But here the problem is by using this TranslateAnimation we can move the views only in straight lines...
If you want to move views in customized way  like(Curve ,circle)...Then you need to use custom views and canvas , where you can pass x and y coordinates while drawing and invalidating the view. You need to override the following method while extending the View class. The changeViewCoordinates() method here can change the x,y coordinates in a curve.

public void onDraw(Canvas aCanvas){  
           aCanvas.drawBitmap(bitmap,x,y,null);  
          changeViewCoordinates();  
           invalidate()
}
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question