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 8743643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:42:52+00:00 2026-06-13T11:42:52+00:00

In R&D for a related view I’m attempting to build , I started a

  • 0

In R&D for a related view I’m attempting to build, I started a simple project to grasp how to do more of the basic drawing “stuff” before getting ahead of myself.

Like my other question states, there’s a lot of information out for SurfaceView threading and animation, but I feel for this application, that may be overkill. I’ll be showing somewhere between 10 and perhaps hundreds of the final View on screen at once, and from what I gather about SurfaceView it’s usually used as the main view of an Activity (game screen, etc).

This R&D app draws a few circles, and calculates the distance between the target (red lines) and the previous position (white lines):

Screenshot of the current implementation

My onDraw is pretty straightforward, but I’m having quite a hard time figuring out how to implement a Thread or Handler, or any sort of non-UI loop to calculate the values between the target and the main circle.

I have a private static inner Thread that I thought would be easy, but no dice. The latest Frankencode:

private static class DragThread extends Thread {
    private DragTest view;
    private boolean animate;

    private float currentY, targetY, delta, inc;

    public DragThread(View v){
        view = (DragTest)v;
        targetY = view.mTargetData.getY();
        currentY = view.mMainData.getY();
    }
    public void run(){
        while(Math.abs(currentY - targetY) >= 0){
            view.mMainData.setY(currentY + 10f);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {

            }finally{
                view.postInvalidate();    
            }
        }
        Log.e(TAG, "Loop finished");
    }
}

mMainData and mTargetData are just POJOs holding the positional values of each circle, which my onDraw uses to update the position:

mMainData = new CircleData(startXposition, startYposition, radius);

…and retrieved using standard getters.

Essentially, I know I’ll need to start the loop logic when I lift my finger, but I’ve gotten a few errors ranging from “Thread Already Started”, to freezes and crashes. Handlers give me leak warnings… man. I’m spent.

Here’s the onTouchEvent for my view, with explanation of each event:

@Override
public boolean onTouchEvent(MotionEvent event) {
    int action = event.getAction();

    if(action == MotionEvent.ACTION_DOWN){

        // set some flags for drawing, update "hero" circle Y position
        // based off event data
    }else if(action == MotionEvent.ACTION_UP){

        // reset flags that dictate ghost circle drawing, etc. and invalidate
        // I think I need to start the loop here, but how?! 
        // new Thread().start()? Some sort of Handler? GAH!

    }else if(action == MotionEvent.ACTION_MOVE){
        // update mMainData Y position which is passed into onDraw, invalidate to reflect movement changes
    }        
    return false;
}
  • 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-06-13T11:42:53+00:00Added an answer on June 13, 2026 at 11:42 am

    Based on this article, the solution was apparently staring me in the face, but I thought it was harder than it really is.

    Final solution for the sample application in question is to have the view implement Runnable, set up a new animation Thread when the user lifts their finger, and use a Scroller to compute the offset.

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        int action = event.getAction();
    
        if(action == MotionEvent.ACTION_DOWN){
            // ...
        }else if(action == MotionEvent.ACTION_UP){
            // ...
    
            startAnimation();
            return true;
        }else if(action == MotionEvent.ACTION_MOVE){
            // ...
        }        
        return false;
    }
    public void run(){
        int start = (int)mMainData.getY();
        int end   = (int)mTargetData.getY();
    
        mScroller.startScroll(0, start, 0, -Math.round(mMainData.getY() - end), 500);
    
        while(canAnimate()){
            while(mScroller.computeScrollOffset()){
                mMainData.setY(mScroller.getCurrY());
                postInvalidate();
            }
            stopAnimation();
        }
    }
    private void startAnimation(){
        mThread = new Thread(this);
        mThread.start();
    }
    private void stopAnimation(){
        animate = false;
    }
    private boolean canAnimate(){
        return animate == true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read and read related Q&A and can't believe that if my custom
Related: see here I've got this command: exec((wget -O http://domain/file.zip && mysql -u user
Related question, about assignment-initialization-declaration. $ javac MatchTest.java MatchTest.java:7: ')' expected for((int i=-1 && String
I am the lead instructor of web & internet related courses on a private
All, This appears to be Firefox related issue (havent tried Opera & IE). I
My RoR app requires users to tick a Terms & Conditions checkbox before uploading
I have a MFC document/view C++ graphics application that does all its drawing to
for seo related reason in my project i have to trap certain search parameters
& is a reserved character in html therefore everywhere I have url's pointing to
& has && . | has || . Why doesn't ^ have ^^ ?

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.