Retrieve position in an AnimationSet

by arnouf » Mon, 03 Nov 2008 02:11:24 GMT

Sponsored Links

I'm writting a small game but I've a BIG problem.
I've a picture where I set animation. The pic goes down and up on
screen. When I click on this pic I would like retrieve his position

When I create the object, it's placed at 0,0...
When it goes down, if I click on it nothing happens. If I click on the
original position, I retrieve my position but it's still 0,0, even if
my pic is on the bottom of the screen!

Find below a part of my code
Animation rootSet = new AnimationSet(true);
                rootSet.setInterpolator(new AccelerateInterpolator());
                float positionYStart = 0;
                int timing = 0;

                while (positionYStart<maxHeight) {
                        // Create and add first child, a motion animation.
                                TranslateAnimation transRight = new 
TranslateAnimation(0,15, 0,

                                TranslateAnimation transLeft = new 
TranslateAnimation(0,-15, 0,

                                timing = timing+speedUp*2;
                                positionYStart = positionYStart+30;

This a class extended ImageView

public MyClass(Drawable d, Context c, int screenWidth){

                super.setFrame(new Random().nextInt(screenWidth), 0, 30,30);

Thanks for your help

Other Threads

1. AudioPool cleanup issues

Hello everyone,

I am developing a game using NDK and I am using the SoundPool to
manage the sounds aspect. Recently I've hit a rather unpleasant
In my code sounds are related to events, and most of them are loops
which are started at a touch event and stopped when the touch is over,
this is an example. All sound ids for SoundPool are loaded prior to
using them only once, then when a sound is needed I call the Play
method in the SoundPool class. Sometimes I have a very large amount of
Play/Stop pairs, for example when quickly tapping a fire button, which
would otherwise just keep looping a machinegun if the finger would
stick to the screen. As far as I've read in the reference, the Stop
method called on a stream ID should cleanup the native memory needed
for the process. Problem is after some 20-30 Play/Stop pairs, every
call of Play raises this error and the sound does not play.

03-05 15:52:14.912: ERROR/AudioTrack(3991): AudioFlinger could not
create track, status: -12
03-05 15:52:14.912: ERROR/SoundPool(3991): Error creating AudioTrack
03-05 15:52:15.073: ERROR/AudioFlinger(52): not enough memory for
AudioTrack size=79860
03-05 15:52:15.073: DEBUG/MemoryDealer(52):   AudioTrack (0x17718,
03-05 15:52:15.073: DEBUG/MemoryDealer(52):     0: 00015958 |
0x00000000 | 0x00003940 | F
03-05 15:52:15.073: DEBUG/MemoryDealer(52):     1: 00012dc0 |
0x00003940 | 0x00003040 | A
.... more stuff here...
03-05 15:52:15.073: DEBUG/MemoryDealer(52):    17: 000137a0 |
0x000DD820 | 0x0000DE20 | A
03-05 15:52:15.073: DEBUG/MemoryDealer(52):    18: 00013940 |
0x000EB640 | 0x0000DE20 | A
03-05 15:52:15.073: DEBUG/MemoryDealer(52):    19: 00013af8 |
0x000F9460 | 0x00006BA0 | F
03-05 15:52:15.073: DEBUG/MemoryDealer(52):   size allocated: 957344
(934 KB)

I get a valid stream id from play but the sound never shows up. If I
stop the sound requesting after some time the sound would play again,
like some memory has been freed up in the meantime, but with little
Play/Stop calling I hit the out of memory warning again. I've even
added an extra Stop on streams every time I pick up play (stream ids
are related to sound ids in a data structure, usually I don't have
more then one stream ID per sound ID) to no resolve.

It just seems the AudioPool is not really cleaning stuff up when the
Stop is called, but rather lately and the SoundPool just runs out of
memory for playing new streams, although the number of streams should
be constant from my code. I find this quite annoying because all the
sounds are loaded only once. If I get out of mem because of the
overhead generated by 50 Play/Stop requests for different sounds
something is wrong.

I've searched the web for similar behavior but I could not find
anything regarding this issue. I don't see any way to rewind a stream
and don't just call Stop/Play over again. I haven't yet tried to do a
full release() from time to time, but this solution doesn't strike me
as very good one, I am not very keen on reloading 12 sound files every
40 Play requests during gameplay.

I've checked they I always call stop for started streams before
calling a new play for the same sound id, also the fact that sounds
recover after some time seems to point that the issue is not in my
code. I would expect issues to be permanent if I had any kind of leaks
regarding sound streams.

Any suggestion would be highly appreciated.



2. AsyncTask and passing message back to UI Thread

I have a simple app and I'm using the AsyncTask to test out a
background process, for clearness purposes I've opted to put my
AsyncTask in a separate class rather than in an inner class, which
where my problems begin, this is my AsyncTask

package org.tutorial.test101.tasks;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

public class LoginTask extends AsyncTask<String, String, String> {

        Context ctx;
        ProgressDialog pDialog;

        public LoginTask(Context context){
        protected String doInBackground(String... params) {
                Log.i("LOGGER", "Starting...");
                }catch(InterruptedException e){

                return null;

        protected void onPostExecute(String result) {

                        Log.i("LOGGER", "Done...");

        protected void onPreExecute() {
                pDialog=new ProgressDialog(ctx);
                pDialog.setMessage("doing stuff..");


What I'd like is that once the task is complete, I do something in the
UI thread may be start another activity or even display a Toast saying
activity complete. I know I can't start a new Activity in the
onPostExecute() so I need to start it in the UI thread any idea how I
can do this? This is my Activity that starts the AsyncTask

package org.tutorial.test101.activities;

import org.tutorial.test101.tasks.LoginTask;

import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Test101 extends Activity{
        private Button btnLogin;
        private LoginTask mLoginTask;
        private Context context=this;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        btnLogin.setOnClickListener(new OnClickListener(){

                        public void onClick(View v) {
                                        mLoginTask=new LoginTask(context);





3. Problems capturing keys

4. My first android application. i need advise

5. How can i show a prefilled contacts screen on android 2.0

6. SmsManager and double SMS message

7. How to create an icon on the status bar ?