Solved

x y coordinates  animation

Posted on 2012-03-28
3
1,246 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
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Glassfish admin console not working 1 53
moto 4g file transfer 12 74
Active Directory Account getting mysteriously locked 13 61
Website checklist for browser compatibility? 2 37
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

679 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