Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7440315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:49:58+00:00 2026-05-29T10:49:58+00:00

Please help I have 3 ImageViews and I can move that 3 views with

  • 0

Please help
I have 3 ImageViews and I can move that 3 views with TranslateAnimation by using 3 Runnables.
Here is my code:

private Runnable run1= new Runnable() {   
    public void run() {
        if(t1)
        {
            LayoutParams params1=(LayoutParams) l1.getLayoutParams();
            params1.x=x1;
            params1.y=y1;
            l1.setLayoutParams(params1);
            x2=r.nextInt(720-80)+80;
            y2=r.nextInt(400-80)+80;

        TranslateAnimation ta1 = new TranslateAnimation(0, x2-x1, 0, y2-y1 );
        ta1.setDuration(800);
        ta1.setFillAfter(true);
        l1.startAnimation(ta1);
        x1=x2;
        y1=y2;

        handler.postDelayed(run1, 800);

        }
    }

};
then I have Run2, run3 like this, and run them by calling

    this.runOnUiThread(run1);
    this.runOnUiThread(run2);
    this.runOnUiThread(run3);

in OnCreate

Then I have Array with int c ImageViews(eg c=10, then c=20…)

for(j=0;j<c;j++)    
    { 

        mp[j] = MediaPlayer.create(getApplicationContext(), soundArray[i[j]]); 
        images[j]=new ImageView(getBaseContext());
        lp[j]=new LayoutParams(50,50, x1[j], y1[j]);
        images[j].setLayoutParams(lp[j]);
        images[j].setBackgroundResource(imgArray[i[j]]);
        images[j].setId(j);
        images[j].setOnClickListener((OnClickListener)this);
        abs.addView(images[j]);
    }

How can I do something like this with it?

How to create many Runnables dynamically?

This code not working

for(j=0;j<c;j++)    
    {
        run[j]=new Runnable()
        {
            public void run() {
                if(t[j])

                {

                    params[j]=(LayoutParams) images[j].getLayoutParams();
                    params[j].x=x1[j];
                    params[j].y=y1[j];
                    images[j].setLayoutParams(params[j]);

                    x2[j]=r.nextInt(720-80)+80;
                    y2[j]=r.nextInt(400-80)+80;

                    ta[j] = new TranslateAnimation(0, x2[j]-x1[j], 0, y2[j]-y1[j] );
                    ta[j].setDuration(200);
                    ta[j].setFillAfter(true);
                    images[j].startAnimation(ta[j]);
                    x1[j]=x2[j];
                    y1[j]=y2[j];

                    handler.postDelayed(run[j], 200);   
                }
            }

      };
    for(j=0;j<c;j++)    
    {
        this.runOnUiThread(run[j]);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:49:59+00:00Added an answer on May 29, 2026 at 10:49 am

    I create separate class. This class should implement Runnable.

    public class Single implements Runnable{
        public ImageView img=new ImageView(getBaseContext());
        public boolean t=true;
        public int x2=0;
        public int y2=0;
    
        public void run() {
            if(t)
    
            {
                LayoutParams params=(LayoutParams) img.getLayoutParams();
                params.x=x2;
                params.y=y2;
                img.setLayoutParams(params);
    
                x2=r.nextInt(randX);
                y2=r.nextInt(randY);
    
                TranslateAnimation ta = new TranslateAnimation(0, x2-params.x, 0, y2-params.y );
                ta.setDuration(1000);
                ta.setFillAfter(true);
                img.startAnimation(ta);
    
                handler.postDelayed(this, 1000);    
            }
        }
    
    }
    

    Then I can dynamically create array of objects of this class and for each object run animation.

    public Single[] images;
    images=new Single[c];
    
        for(j=0;j<c;j++)    
        {
            images[j]=new Single();
            images[j].x2=r.nextInt(randX);
            images[j].y2=r.nextInt(randY);
            images[j].t=true;
        }
        for(int j1=0;j1<c;j1++) 
        {
    
            this.runOnUiThread(images[j1]);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me out here because im getting kind of confused.. I have a
In my view i have ImageView.If i click ,it should open nextview. Please help
may be too simple groovy question but....please help i have a list like this:
Please help! Background info I have a WPF application which accesses a SQL Server
Please help! I have been grappling with this error for days and I cannot
Please help! I have some form elements in a div on a page: <div
Please help regarding the following issue. I have enabled the Block popup option in
Someone please help. I have an interesting issue. I am trying to implement an
Please help me about this issue... In my application i have calender where user
please help me to parse xml from another xml... i have this xml named

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.