Solved

x y coordinates  animation

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tomcat: Unable to run tomcat service. 2 23
throw exception 21 58
maven module vs maven project 3 46
Is there a simpler dropbox system? 10 34
Often, people trade privacy and security for convenience. However in today's concrete jungle, this is an extremely foolish decision considering the vast amount of technologies being used against consumer interest. First off, I won't waste any time e…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

856 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